mantis_ca.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. Mantis PCI bridge driver
  3. Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "mantis_common.h"
  17. #include "mantis_link.h"
  18. #include "mantis_hif.h"
  19. static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr)
  20. {
  21. struct mantis_ca *ca = en50221->data;
  22. struct mantis_pci *mantis = ca->ca_priv;
  23. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot);
  24. if (slot != 0)
  25. return -EINVAL;
  26. return mantis_hif_read_mem(ca, addr);
  27. }
  28. static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data)
  29. {
  30. struct mantis_ca *ca = en50221->data;
  31. struct mantis_pci *mantis = ca->ca_priv;
  32. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot);
  33. if (slot != 0)
  34. return -EINVAL;
  35. return mantis_hif_write_mem(ca, addr, data);
  36. }
  37. static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr)
  38. {
  39. struct mantis_ca *ca = en50221->data;
  40. struct mantis_pci *mantis = ca->ca_priv;
  41. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot);
  42. if (slot != 0)
  43. return -EINVAL;
  44. return mantis_hif_read_iom(ca, addr);
  45. }
  46. static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data)
  47. {
  48. struct mantis_ca *ca = en50221->data;
  49. struct mantis_pci *mantis = ca->ca_priv;
  50. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot);
  51. if (slot != 0)
  52. return -EINVAL;
  53. return mantis_hif_write_iom(ca, addr, data);
  54. }
  55. static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
  56. {
  57. struct mantis_ca *ca = en50221->data;
  58. struct mantis_pci *mantis = ca->ca_priv;
  59. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot);
  60. udelay(500); /* Wait.. */
  61. mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */
  62. udelay(500);
  63. mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */
  64. msleep(1000);
  65. return 0;
  66. }
  67. static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
  68. {
  69. struct mantis_ca *ca = en50221->data;
  70. struct mantis_pci *mantis = ca->ca_priv;
  71. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot);
  72. return 0;
  73. }
  74. static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot)
  75. {
  76. struct mantis_ca *ca = en50221->data;
  77. struct mantis_pci *mantis = ca->ca_priv;
  78. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): TS control", slot);
  79. return 0;
  80. }
  81. static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open)
  82. {
  83. struct mantis_ca *ca = en50221->data;
  84. struct mantis_pci *mantis = ca->ca_priv;
  85. dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot);
  86. if (ca->slot_state == MODULE_INSERTED)
  87. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  88. return 0;
  89. }
  90. int mantis_ca_init(struct mantis_pci *mantis)
  91. {
  92. struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter;
  93. struct mantis_ca *ca;
  94. int ca_flags = 0, result;
  95. dprintk(verbose, MANTIS_DEBUG, 1, "Initializing Mantis CA");
  96. if (!(ca = kzalloc(sizeof (struct mantis_ca), GFP_KERNEL))) {
  97. dprintk(verbose, MANTIS_ERROR, 1, "Out of memory!, exiting ..");
  98. result = -ENOMEM;
  99. goto err;
  100. }
  101. ca->ca_priv = mantis;
  102. mantis->mantis_ca = ca;
  103. /* register CA interface */
  104. ca->en50221.owner = THIS_MODULE;
  105. ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem;
  106. ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem;
  107. ca->en50221.read_cam_control = mantis_ca_read_cam_ctl;
  108. ca->en50221.write_cam_control = mantis_ca_write_cam_ctl;
  109. ca->en50221.slot_reset = mantis_ca_slot_reset;
  110. ca->en50221.slot_shutdown = mantis_ca_slot_shutdown;
  111. ca->en50221.slot_ts_enable = mantis_ts_control;
  112. ca->en50221.poll_slot_status = mantis_slot_status;
  113. ca->en50221.data = ca;
  114. dprintk(verbose, MANTIS_ERROR, 1, "Registering EN50221 device");
  115. if ((result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1)) != 0) {
  116. dprintk(verbose, MANTIS_ERROR, 1, "EN50221: Initialization failed");
  117. goto err;
  118. }
  119. dprintk(verbose, MANTIS_ERROR, 1, "Registered EN50221 device");
  120. mantis_evmgr_init(ca);
  121. return 0;
  122. err:
  123. kfree(ca);
  124. return result;
  125. }
  126. void mantis_ca_exit(struct mantis_pci *mantis)
  127. {
  128. struct mantis_ca *ca = mantis->mantis_ca;
  129. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis CA exit");
  130. mantis_evmgr_exit(ca);
  131. dprintk(verbose, MANTIS_ERROR, 1, "Unregistering EN50221 device");
  132. dvb_ca_en50221_release(&ca->en50221);
  133. kfree(ca);
  134. }