mantis_ca.c 5.7 KB

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