common_ese.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /******************************************************************************
  2. * Copyright (C) 2020-2021 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_CMD | NCI_PROP_MSG_GID)
  25. #define NCI_PROP_MSG_RSP (NCI_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_MS (3000)
  36. /* guard time to reboot after reset */
  37. #define ESE_CLD_RST_REBOOT_GUARD_TIME_MS (50)
  38. /* sources of reset protection and cold reset */
  39. enum reset_source {
  40. SRC_SPI = 0,
  41. SRC_NFC = 0x10,
  42. SRC_OTHER = 0x20,
  43. SRC_NONE = 0x80,
  44. };
  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) || \
  66. IS_SRC_NFC(arg) || \
  67. IS_SRC_OTHER(arg))
  68. #define IS_SRC_VALID_PROT(arg) (IS_SRC_SPI(arg) || \
  69. IS_SRC_NFC(arg))
  70. #define IS_RST(arg, type) ((arg & 0xF) == type)
  71. #define IS_CLD_RST_REQ(arg) IS_RST(arg, ESE_CLD_RST)
  72. #define IS_RST_PROT_EN_REQ(arg) IS_RST(arg, ESE_RST_PROT_EN)
  73. #define IS_RST_PROT_DIS_REQ(arg) IS_RST(arg, ESE_RST_PROT_DIS)
  74. #define IS_RST_PROT_REQ(arg) (IS_RST_PROT_EN_REQ(arg) || \
  75. IS_RST_PROT_DIS_REQ(arg))
  76. /* This macro evaluates to 1 if prop cmd response is received */
  77. #define IS_PROP_CMD_RSP(buf) ((buf[0] == NCI_PROP_MSG_RSP) && \
  78. ((buf[1] == CLD_RST_OID) || \
  79. (buf[1] == RST_PROT_OID)))
  80. void wakeup_on_prop_rsp(struct nfc_dev *nfc_dev, uint8_t *buf);
  81. int nfc_ese_pwr(struct nfc_dev *nfc_dev, unsigned long arg);
  82. void ese_cold_reset_release(struct nfc_dev *nfc_dev);
  83. void common_ese_init(struct nfc_dev *nfc_dev);
  84. void common_ese_exit(struct nfc_dev *nfc_dev);
  85. #if IS_ENABLED(CONFIG_SAMSUNG_NFC)
  86. void ese_set_spi_pinctrl_for_ese_off(void *p61);
  87. #endif
  88. #endif /* _COMMON_ESE_H_ */