mei.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/module.h>
  20. #include <linux/mod_devicetable.h>
  21. #include <linux/nfc.h>
  22. #include <net/nfc/hci.h>
  23. #include <net/nfc/llc.h>
  24. #include "../mei_phy.h"
  25. #include "microread.h"
  26. #define MICROREAD_DRIVER_NAME "microread"
  27. static int microread_mei_probe(struct mei_cl_device *cldev,
  28. const struct mei_cl_device_id *id)
  29. {
  30. struct nfc_mei_phy *phy;
  31. int r;
  32. pr_info("Probing NFC microread\n");
  33. phy = nfc_mei_phy_alloc(cldev);
  34. if (!phy) {
  35. pr_err("Cannot allocate memory for microread mei phy.\n");
  36. return -ENOMEM;
  37. }
  38. r = microread_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
  39. MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
  40. &phy->hdev);
  41. if (r < 0) {
  42. nfc_mei_phy_free(phy);
  43. return r;
  44. }
  45. return 0;
  46. }
  47. static int microread_mei_remove(struct mei_cl_device *cldev)
  48. {
  49. struct nfc_mei_phy *phy = mei_cldev_get_drvdata(cldev);
  50. microread_remove(phy->hdev);
  51. nfc_mei_phy_free(phy);
  52. return 0;
  53. }
  54. static struct mei_cl_device_id microread_mei_tbl[] = {
  55. { MICROREAD_DRIVER_NAME, MEI_NFC_UUID, MEI_CL_VERSION_ANY},
  56. /* required last entry */
  57. { }
  58. };
  59. MODULE_DEVICE_TABLE(mei, microread_mei_tbl);
  60. static struct mei_cl_driver microread_driver = {
  61. .id_table = microread_mei_tbl,
  62. .name = MICROREAD_DRIVER_NAME,
  63. .probe = microread_mei_probe,
  64. .remove = microread_mei_remove,
  65. };
  66. static int microread_mei_init(void)
  67. {
  68. int r;
  69. pr_debug(DRIVER_DESC ": %s\n", __func__);
  70. r = mei_cldev_driver_register(&microread_driver);
  71. if (r) {
  72. pr_err(MICROREAD_DRIVER_NAME ": driver registration failed\n");
  73. return r;
  74. }
  75. return 0;
  76. }
  77. static void microread_mei_exit(void)
  78. {
  79. mei_cldev_driver_unregister(&microread_driver);
  80. }
  81. module_init(microread_mei_init);
  82. module_exit(microread_mei_exit);
  83. MODULE_LICENSE("GPL");
  84. MODULE_DESCRIPTION(DRIVER_DESC);