mei.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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, 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 "pn544.h"
  27. #define PN544_DRIVER_NAME "pn544"
  28. static int pn544_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 pn544\n");
  34. phy = nfc_mei_phy_alloc(device);
  35. if (!phy) {
  36. pr_err("Cannot allocate memory for pn544 mei phy.\n");
  37. return -ENOMEM;
  38. }
  39. r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME,
  40. MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD,
  41. NULL, &phy->hdev);
  42. if (r < 0) {
  43. nfc_mei_phy_free(phy);
  44. return r;
  45. }
  46. return 0;
  47. }
  48. static int pn544_mei_remove(struct mei_cl_device *device)
  49. {
  50. struct nfc_mei_phy *phy = mei_cl_get_drvdata(device);
  51. pr_info("Removing pn544\n");
  52. pn544_hci_remove(phy->hdev);
  53. nfc_mei_phy_free(phy);
  54. return 0;
  55. }
  56. static struct mei_cl_device_id pn544_mei_tbl[] = {
  57. { PN544_DRIVER_NAME },
  58. /* required last entry */
  59. { }
  60. };
  61. MODULE_DEVICE_TABLE(mei, pn544_mei_tbl);
  62. static struct mei_cl_driver pn544_driver = {
  63. .id_table = pn544_mei_tbl,
  64. .name = PN544_DRIVER_NAME,
  65. .probe = pn544_mei_probe,
  66. .remove = pn544_mei_remove,
  67. };
  68. static int pn544_mei_init(void)
  69. {
  70. int r;
  71. pr_debug(DRIVER_DESC ": %s\n", __func__);
  72. r = mei_cl_driver_register(&pn544_driver);
  73. if (r) {
  74. pr_err(PN544_DRIVER_NAME ": driver registration failed\n");
  75. return r;
  76. }
  77. return 0;
  78. }
  79. static void pn544_mei_exit(void)
  80. {
  81. mei_cl_driver_unregister(&pn544_driver);
  82. }
  83. module_init(pn544_mei_init);
  84. module_exit(pn544_mei_exit);
  85. MODULE_LICENSE("GPL");
  86. MODULE_DESCRIPTION(DRIVER_DESC);