digital_core.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * NFC Digital Protocol stack
  3. * Copyright (c) 2013, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include "digital.h"
  17. static int digital_start_poll(struct nfc_dev *nfc_dev, __u32 im_protocols,
  18. __u32 tm_protocols)
  19. {
  20. return -EOPNOTSUPP;
  21. }
  22. static void digital_stop_poll(struct nfc_dev *nfc_dev)
  23. {
  24. }
  25. static int digital_dev_up(struct nfc_dev *nfc_dev)
  26. {
  27. return -EOPNOTSUPP;
  28. }
  29. static int digital_dev_down(struct nfc_dev *nfc_dev)
  30. {
  31. return -EOPNOTSUPP;
  32. }
  33. static int digital_dep_link_up(struct nfc_dev *nfc_dev,
  34. struct nfc_target *target,
  35. __u8 comm_mode, __u8 *gb, size_t gb_len)
  36. {
  37. return -EOPNOTSUPP;
  38. }
  39. static int digital_dep_link_down(struct nfc_dev *nfc_dev)
  40. {
  41. return -EOPNOTSUPP;
  42. }
  43. static int digital_activate_target(struct nfc_dev *nfc_dev,
  44. struct nfc_target *target, __u32 protocol)
  45. {
  46. return -EOPNOTSUPP;
  47. }
  48. static void digital_deactivate_target(struct nfc_dev *nfc_dev,
  49. struct nfc_target *target)
  50. {
  51. }
  52. static int digital_tg_send(struct nfc_dev *dev, struct sk_buff *skb)
  53. {
  54. return -EOPNOTSUPP;
  55. }
  56. static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target,
  57. struct sk_buff *skb, data_exchange_cb_t cb,
  58. void *cb_context)
  59. {
  60. return -EOPNOTSUPP;
  61. }
  62. static struct nfc_ops digital_nfc_ops = {
  63. .dev_up = digital_dev_up,
  64. .dev_down = digital_dev_down,
  65. .start_poll = digital_start_poll,
  66. .stop_poll = digital_stop_poll,
  67. .dep_link_up = digital_dep_link_up,
  68. .dep_link_down = digital_dep_link_down,
  69. .activate_target = digital_activate_target,
  70. .deactivate_target = digital_deactivate_target,
  71. .tm_send = digital_tg_send,
  72. .im_transceive = digital_in_send,
  73. };
  74. struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
  75. __u32 supported_protocols,
  76. __u32 driver_capabilities,
  77. int tx_headroom, int tx_tailroom)
  78. {
  79. struct nfc_digital_dev *ddev;
  80. if (!ops->in_configure_hw || !ops->in_send_cmd || !ops->tg_listen ||
  81. !ops->tg_configure_hw || !ops->tg_send_cmd || !ops->abort_cmd ||
  82. !ops->switch_rf)
  83. return NULL;
  84. ddev = kzalloc(sizeof(struct nfc_digital_dev), GFP_KERNEL);
  85. if (!ddev) {
  86. PR_ERR("kzalloc failed");
  87. return NULL;
  88. }
  89. ddev->driver_capabilities = driver_capabilities;
  90. ddev->ops = ops;
  91. ddev->tx_headroom = tx_headroom;
  92. ddev->tx_tailroom = tx_tailroom;
  93. ddev->nfc_dev = nfc_allocate_device(&digital_nfc_ops, ddev->protocols,
  94. ddev->tx_headroom,
  95. ddev->tx_tailroom);
  96. if (!ddev->nfc_dev) {
  97. PR_ERR("nfc_allocate_device failed");
  98. goto free_dev;
  99. }
  100. nfc_set_drvdata(ddev->nfc_dev, ddev);
  101. return ddev;
  102. free_dev:
  103. kfree(ddev);
  104. return NULL;
  105. }
  106. EXPORT_SYMBOL(nfc_digital_allocate_device);
  107. void nfc_digital_free_device(struct nfc_digital_dev *ddev)
  108. {
  109. nfc_free_device(ddev->nfc_dev);
  110. kfree(ddev);
  111. }
  112. EXPORT_SYMBOL(nfc_digital_free_device);
  113. int nfc_digital_register_device(struct nfc_digital_dev *ddev)
  114. {
  115. return nfc_register_device(ddev->nfc_dev);
  116. }
  117. EXPORT_SYMBOL(nfc_digital_register_device);
  118. void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
  119. {
  120. nfc_unregister_device(ddev->nfc_dev);
  121. }
  122. EXPORT_SYMBOL(nfc_digital_unregister_device);
  123. MODULE_LICENSE("GPL");