common_ese.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /******************************************************************************
  2. * Copyright (C) 2020 NXP
  3. * *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  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. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. ******************************************************************************/
  19. #ifndef _COMMON_ESE_H_
  20. #define _COMMON_ESE_H_
  21. #include "common.h"
  22. /*nci prop msg 1st byte*/
  23. #define NCI_PROP_MSG_GID 0x0F
  24. #define NCI_PROP_MSG_CMD (NCI_MSG_CMD | NCI_PROP_MSG_GID)
  25. #define NCI_PROP_MSG_RSP (NCI_MSG_RSP | NCI_PROP_MSG_GID)
  26. /*nci prop msg 2nd byte*/
  27. #define CLD_RST_OID 0x1E
  28. #define RST_PROT_OID 0x1F
  29. /*nci prop msg 3rd byte*/
  30. #define CLD_RST_PAYLOAD_SIZE 0x00
  31. #define RST_PROT_PAYLOAD_SIZE 0x01
  32. /*nci prop msg response length*/
  33. #define NCI_PROP_MSG_RSP_LEN 0x04
  34. /*cold reset guard time to allow back to back cold reset after some time*/
  35. #define ESE_CLD_RST_GUARD_TIME (3000) //3s
  36. /*guard time to reboot after reset*/
  37. #define ESE_CLD_RST_REBOOT_GUARD_TIME (50) //50ms
  38. /*sources of reset protection and cold reset*/
  39. typedef enum reset_source {
  40. SRC_SPI = 0,
  41. SRC_NFC = 0x10,
  42. SRC_OTHER = 0x20,
  43. SRC_NONE = 0x80,
  44. } reset_source_t;
  45. enum ese_ioctl_request {
  46. ESE_POWER_ON = 0, /* eSE POWER ON */
  47. ESE_POWER_OFF, /* eSE POWER OFF */
  48. ESE_POWER_STATE, /* eSE GET POWER STATE */
  49. /*ese reset requests from eSE service/hal/driver */
  50. ESE_CLD_RST, /* eSE COLD RESET */
  51. ESE_RST_PROT_EN, /* eSE RESET PROTECTION ENABLE */
  52. ESE_RST_PROT_DIS, /* eSE RESET PROTECTION DISABLE */
  53. /*similar ese reset requests from nfc service/hal/driver */
  54. ESE_CLD_RST_NFC = ESE_CLD_RST | SRC_NFC,
  55. ESE_RST_PROT_EN_NFC = ESE_RST_PROT_EN | SRC_NFC,
  56. ESE_RST_PROT_DIS_NFC = ESE_RST_PROT_DIS | SRC_NFC,
  57. /*similar ese reset requests from other service/hal/driver */
  58. ESE_CLD_RST_OTHER = ESE_CLD_RST | SRC_OTHER,
  59. };
  60. #define GET_SRC(arg) (arg & 0xF0)
  61. #define IS_SRC(arg, src) (GET_SRC(arg) == src)
  62. #define IS_SRC_SPI(arg) IS_SRC(arg, SRC_SPI)
  63. #define IS_SRC_NFC(arg) IS_SRC(arg, SRC_NFC)
  64. #define IS_SRC_OTHER(arg) IS_SRC(arg, SRC_OTHER)
  65. #define IS_SRC_VALID(arg) (IS_SRC_SPI(arg) || IS_SRC_NFC(arg) || \
  66. IS_SRC_OTHER(arg))
  67. #define IS_SRC_VALID_PROT(arg) (IS_SRC_SPI(arg) || IS_SRC_NFC(arg))
  68. #define IS_RST(arg, type) ((arg & 0xF) == type)
  69. #define IS_CLD_RST_REQ(arg) IS_RST(arg, ESE_CLD_RST)
  70. #define IS_RST_PROT_EN_REQ(arg) IS_RST(arg, ESE_RST_PROT_EN)
  71. #define IS_RST_PROT_DIS_REQ(arg) IS_RST(arg, ESE_RST_PROT_DIS)
  72. #define IS_RST_PROT_REQ(arg) (IS_RST_PROT_EN_REQ(arg) || IS_RST_PROT_DIS_REQ(arg))
  73. /* This macro evaluates to 1 if prop cmd response is received */
  74. #define IS_PROP_CMD_RSP(buf) \
  75. ((NCI_PROP_MSG_RSP == buf[0]) && ((CLD_RST_OID == buf[1]) || \
  76. (RST_PROT_OID == buf[1])))
  77. void wakeup_on_prop_rsp(nfc_dev_t *nfc_dev, uint8_t *buf);
  78. int nfc_ese_pwr(nfc_dev_t *nfc_dev, unsigned long arg);
  79. void common_ese_on_hard_reset(nfc_dev_t *nfc_dev);
  80. void common_ese_init(nfc_dev_t *nfc_dev);
  81. void common_ese_exit(nfc_dev_t *nfc_dev);
  82. #endif /* _COMMON_ESE_H_ */