mantis_ca.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. Mantis PCI bridge driver
  3. Copyright (C) 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 <linux/signal.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include "dmxdev.h"
  20. #include "dvbdev.h"
  21. #include "dvb_demux.h"
  22. #include "dvb_frontend.h"
  23. #include "dvb_net.h"
  24. #include "mantis_common.h"
  25. #include "mantis_link.h"
  26. #include "mantis_hif.h"
  27. #include "mantis_reg.h"
  28. #include "mantis_ca.h"
  29. static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr)
  30. {
  31. struct mantis_ca *ca = en50221->data;
  32. struct mantis_pci *mantis = ca->ca_priv;
  33. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot);
  34. if (slot != 0)
  35. return -EINVAL;
  36. return mantis_hif_read_mem(ca, addr);
  37. }
  38. static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data)
  39. {
  40. struct mantis_ca *ca = en50221->data;
  41. struct mantis_pci *mantis = ca->ca_priv;
  42. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot);
  43. if (slot != 0)
  44. return -EINVAL;
  45. return mantis_hif_write_mem(ca, addr, data);
  46. }
  47. static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr)
  48. {
  49. struct mantis_ca *ca = en50221->data;
  50. struct mantis_pci *mantis = ca->ca_priv;
  51. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot);
  52. if (slot != 0)
  53. return -EINVAL;
  54. return mantis_hif_read_iom(ca, addr);
  55. }
  56. static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data)
  57. {
  58. struct mantis_ca *ca = en50221->data;
  59. struct mantis_pci *mantis = ca->ca_priv;
  60. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot);
  61. if (slot != 0)
  62. return -EINVAL;
  63. return mantis_hif_write_iom(ca, addr, data);
  64. }
  65. static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
  66. {
  67. struct mantis_ca *ca = en50221->data;
  68. struct mantis_pci *mantis = ca->ca_priv;
  69. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot);
  70. udelay(500); /* Wait.. */
  71. mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */
  72. udelay(500);
  73. mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */
  74. msleep(1000);
  75. dvb_ca_en50221_camready_irq(&ca->en50221, 0);
  76. return 0;
  77. }
  78. static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
  79. {
  80. struct mantis_ca *ca = en50221->data;
  81. struct mantis_pci *mantis = ca->ca_priv;
  82. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot);
  83. return 0;
  84. }
  85. static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot)
  86. {
  87. struct mantis_ca *ca = en50221->data;
  88. struct mantis_pci *mantis = ca->ca_priv;
  89. dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot);
  90. /* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */
  91. return 0;
  92. }
  93. static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open)
  94. {
  95. struct mantis_ca *ca = en50221->data;
  96. struct mantis_pci *mantis = ca->ca_priv;
  97. dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot);
  98. if (ca->slot_state == MODULE_INSERTED) {
  99. dprintk(MANTIS_DEBUG, 1, "CA Module present and ready");
  100. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  101. } else {
  102. dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready");
  103. }
  104. return 0;
  105. }
  106. int mantis_ca_init(struct mantis_pci *mantis)
  107. {
  108. struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter;
  109. struct mantis_ca *ca;
  110. int ca_flags = 0, result;
  111. dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA");
  112. ca = kzalloc(sizeof(struct mantis_ca), GFP_KERNEL);
  113. if (!ca) {
  114. dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting ..");
  115. result = -ENOMEM;
  116. goto err;
  117. }
  118. ca->ca_priv = mantis;
  119. mantis->mantis_ca = ca;
  120. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE;
  121. /* register CA interface */
  122. ca->en50221.owner = THIS_MODULE;
  123. ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem;
  124. ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem;
  125. ca->en50221.read_cam_control = mantis_ca_read_cam_ctl;
  126. ca->en50221.write_cam_control = mantis_ca_write_cam_ctl;
  127. ca->en50221.slot_reset = mantis_ca_slot_reset;
  128. ca->en50221.slot_shutdown = mantis_ca_slot_shutdown;
  129. ca->en50221.slot_ts_enable = mantis_ts_control;
  130. ca->en50221.poll_slot_status = mantis_slot_status;
  131. ca->en50221.data = ca;
  132. mutex_init(&ca->ca_lock);
  133. init_waitqueue_head(&ca->hif_data_wq);
  134. init_waitqueue_head(&ca->hif_opdone_wq);
  135. init_waitqueue_head(&ca->hif_write_wq);
  136. dprintk(MANTIS_ERROR, 1, "Registering EN50221 device");
  137. result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1);
  138. if (result != 0) {
  139. dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result);
  140. goto err;
  141. }
  142. dprintk(MANTIS_ERROR, 1, "Registered EN50221 device");
  143. mantis_evmgr_init(ca);
  144. return 0;
  145. err:
  146. kfree(ca);
  147. return result;
  148. }
  149. EXPORT_SYMBOL_GPL(mantis_ca_init);
  150. void mantis_ca_exit(struct mantis_pci *mantis)
  151. {
  152. struct mantis_ca *ca = mantis->mantis_ca;
  153. dprintk(MANTIS_DEBUG, 1, "Mantis CA exit");
  154. mantis_evmgr_exit(ca);
  155. dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device");
  156. if (ca)
  157. dvb_ca_en50221_release(&ca->en50221);
  158. kfree(ca);
  159. }
  160. EXPORT_SYMBOL_GPL(mantis_ca_exit);