mantis_ca.c 5.6 KB

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