mei.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * HCI based Driver for Inside Secure microread NFC Chip
  3. *
  4. * Copyright (C) 2013 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the
  17. * Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/mod_devicetable.h>
  22. #include <linux/nfc.h>
  23. #include <net/nfc/hci.h>
  24. #include <net/nfc/llc.h>
  25. #include "../mei_phy.h"
  26. #include "microread.h"
  27. #define MICROREAD_DRIVER_NAME "microread"
  28. static int microread_mei_probe(struct mei_cl_device *device,
  29. const struct mei_cl_device_id *id)
  30. {
  31. struct nfc_mei_phy *phy;
  32. int r;
  33. pr_info("Probing NFC microread\n");
  34. phy = nfc_mei_phy_alloc(device);
  35. if (!phy) {
  36. pr_err("Cannot allocate memory for microread mei phy.\n");
  37. return -ENOMEM;
  38. }
  39. r = mei_cl_register_event_cb(device, nfc_mei_event_cb, phy);
  40. if (r) {
  41. pr_err(MICROREAD_DRIVER_NAME ": event cb registration failed\n");
  42. goto err_out;
  43. }
  44. r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
  45. MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
  46. &phy->hdev);
  47. if (r < 0)
  48. goto err_out;
  49. return 0;
  50. err_out:
  51. nfc_mei_phy_free(phy);
  52. return r;
  53. }
  54. static int microread_mei_remove(struct mei_cl_device *device)
  55. {
  56. struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
  57. pr_info("Removing microread\n");
  58. microread_remove(phy->hdev);
  59. nfc_mei_phy_disable(phy);
  60. nfc_mei_phy_free(phy);
  61. return 0;
  62. }
  63. static struct mei_cl_device_id microread_mei_tbl[] = {
  64. { MICROREAD_DRIVER_NAME },
  65. /* required last entry */
  66. { }
  67. };
  68. MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
  69. static struct mei_cl_driver microread_driver = {
  70. .id_table = microread_mei_tbl,
  71. .name = MICROREAD_DRIVER_NAME,
  72. .probe = microread_mei_probe,
  73. .remove = microread_mei_remove,
  74. };
  75. static int microread_mei_init(void)
  76. {
  77. int r;
  78. pr_debug(DRIVER_DESC ": %s\n", __func__);
  79. r = mei_cl_driver_register(&microread_driver);
  80. if (r) {
  81. pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
  82. return r;
  83. }
  84. return 0;
  85. }
  86. static void microread_mei_exit(void)
  87. {
  88. mei_cl_driver_unregister(&microread_driver);
  89. }
  90. module_init(microread_mei_init);
  91. module_exit(microread_mei_exit);
  92. MODULE_LICENSE("GPL");
  93. MODULE_DESCRIPTION(DRIVER_DESC);