mei.c 2.4 KB

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