Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis PCI bridge driver |
| 3 | |
Manu Abraham | 8825a09 | 2009-12-15 09:13:49 -0300 | [diff] [blame] | 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 21 | #include <linux/signal.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 22 | #include <linux/slab.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 23 | #include <linux/sched.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
| 26 | #include "dmxdev.h" |
| 27 | #include "dvbdev.h" |
| 28 | #include "dvb_demux.h" |
| 29 | #include "dvb_frontend.h" |
| 30 | #include "dvb_net.h" |
| 31 | |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 32 | #include "mantis_common.h" |
| 33 | #include "mantis_link.h" |
| 34 | #include "mantis_hif.h" |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 35 | #include "mantis_reg.h" |
| 36 | |
| 37 | #include "mantis_ca.h" |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 38 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 39 | static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr) |
| 40 | { |
| 41 | struct mantis_ca *ca = en50221->data; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 42 | struct mantis_pci *mantis = ca->ca_priv; |
| 43 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 44 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot); |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 45 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 46 | if (slot != 0) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | return mantis_hif_read_mem(ca, addr); |
| 50 | } |
| 51 | |
| 52 | static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data) |
| 53 | { |
| 54 | struct mantis_ca *ca = en50221->data; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 55 | struct mantis_pci *mantis = ca->ca_priv; |
| 56 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 57 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 58 | |
| 59 | if (slot != 0) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | return mantis_hif_write_mem(ca, addr, data); |
| 63 | } |
| 64 | |
| 65 | static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr) |
| 66 | { |
| 67 | struct mantis_ca *ca = en50221->data; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 68 | struct mantis_pci *mantis = ca->ca_priv; |
| 69 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 70 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 71 | |
| 72 | if (slot != 0) |
| 73 | return -EINVAL; |
| 74 | |
| 75 | return mantis_hif_read_iom(ca, addr); |
| 76 | } |
| 77 | |
| 78 | static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data) |
| 79 | { |
| 80 | struct mantis_ca *ca = en50221->data; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 81 | struct mantis_pci *mantis = ca->ca_priv; |
| 82 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 83 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 84 | |
| 85 | if (slot != 0) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | return mantis_hif_write_iom(ca, addr, data); |
| 89 | } |
| 90 | |
| 91 | static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 92 | { |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 93 | struct mantis_ca *ca = en50221->data; |
| 94 | struct mantis_pci *mantis = ca->ca_priv; |
| 95 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 96 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot); |
Manu Abraham | fb6de9c | 2009-12-04 05:17:46 -0300 | [diff] [blame] | 97 | udelay(500); /* Wait.. */ |
| 98 | mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */ |
| 99 | udelay(500); |
| 100 | mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */ |
| 101 | msleep(1000); |
Manu Abraham | 2ec9b00 | 2009-12-04 05:20:44 -0300 | [diff] [blame] | 102 | dvb_ca_en50221_camready_irq(&ca->en50221, 0); |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 103 | |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 104 | return 0; |
| 105 | } |
| 106 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 107 | static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 108 | { |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 109 | struct mantis_ca *ca = en50221->data; |
| 110 | struct mantis_pci *mantis = ca->ca_priv; |
| 111 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 112 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot); |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 113 | |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 117 | static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 118 | { |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 119 | struct mantis_ca *ca = en50221->data; |
| 120 | struct mantis_pci *mantis = ca->ca_priv; |
| 121 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 122 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot); |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 123 | /* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */ |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 124 | |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 128 | static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 129 | { |
Manu Abraham | 4e9fbee | 2009-12-04 05:11:41 -0300 | [diff] [blame] | 130 | struct mantis_ca *ca = en50221->data; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 131 | struct mantis_pci *mantis = ca->ca_priv; |
| 132 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 133 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot); |
Manu Abraham | 4e9fbee | 2009-12-04 05:11:41 -0300 | [diff] [blame] | 134 | |
Manu Abraham | 5e2a0c9 | 2009-12-04 05:23:17 -0300 | [diff] [blame] | 135 | if (ca->slot_state == MODULE_INSERTED) { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 136 | dprintk(MANTIS_DEBUG, 1, "CA Module present and ready"); |
Manu Abraham | 4e9fbee | 2009-12-04 05:11:41 -0300 | [diff] [blame] | 137 | return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY; |
Manu Abraham | 5e2a0c9 | 2009-12-04 05:23:17 -0300 | [diff] [blame] | 138 | } else { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 139 | dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready"); |
Manu Abraham | 5e2a0c9 | 2009-12-04 05:23:17 -0300 | [diff] [blame] | 140 | } |
Manu Abraham | 4e9fbee | 2009-12-04 05:11:41 -0300 | [diff] [blame] | 141 | |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 142 | return 0; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 143 | } |
| 144 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 145 | int mantis_ca_init(struct mantis_pci *mantis) |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 146 | { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 147 | struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 148 | struct mantis_ca *ca; |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 149 | int ca_flags = 0, result; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 150 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 151 | dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA"); |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 152 | ca = kzalloc(sizeof(struct mantis_ca), GFP_KERNEL); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 153 | if (!ca) { |
| 154 | dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting .."); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 155 | result = -ENOMEM; |
| 156 | goto err; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 157 | } |
| 158 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 159 | ca->ca_priv = mantis; |
| 160 | mantis->mantis_ca = ca; |
| 161 | ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE; |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 162 | /* register CA interface */ |
| 163 | ca->en50221.owner = THIS_MODULE; |
| 164 | ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem; |
| 165 | ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem; |
| 166 | ca->en50221.read_cam_control = mantis_ca_read_cam_ctl; |
| 167 | ca->en50221.write_cam_control = mantis_ca_write_cam_ctl; |
| 168 | ca->en50221.slot_reset = mantis_ca_slot_reset; |
| 169 | ca->en50221.slot_shutdown = mantis_ca_slot_shutdown; |
| 170 | ca->en50221.slot_ts_enable = mantis_ts_control; |
| 171 | ca->en50221.poll_slot_status = mantis_slot_status; |
| 172 | ca->en50221.data = ca; |
| 173 | |
Manu Abraham | 99b55b2 | 2009-12-04 05:34:44 -0300 | [diff] [blame] | 174 | mutex_init(&ca->ca_lock); |
| 175 | |
Manu Abraham | 42f541b | 2009-12-04 05:35:07 -0300 | [diff] [blame] | 176 | init_waitqueue_head(&ca->hif_data_wq); |
| 177 | init_waitqueue_head(&ca->hif_opdone_wq); |
| 178 | init_waitqueue_head(&ca->hif_write_wq); |
| 179 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 180 | dprintk(MANTIS_ERROR, 1, "Registering EN50221 device"); |
| 181 | result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1); |
| 182 | if (result != 0) { |
| 183 | dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 184 | goto err; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 185 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 186 | dprintk(MANTIS_ERROR, 1, "Registered EN50221 device"); |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 187 | mantis_evmgr_init(ca); |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 188 | return 0; |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 189 | err: |
| 190 | kfree(ca); |
| 191 | return result; |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 192 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 193 | EXPORT_SYMBOL_GPL(mantis_ca_init); |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 194 | |
| 195 | void mantis_ca_exit(struct mantis_pci *mantis) |
| 196 | { |
| 197 | struct mantis_ca *ca = mantis->mantis_ca; |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 198 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 199 | dprintk(MANTIS_DEBUG, 1, "Mantis CA exit"); |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 200 | |
| 201 | mantis_evmgr_exit(ca); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 202 | dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device"); |
| 203 | if (ca) |
| 204 | dvb_ca_en50221_release(&ca->en50221); |
Manu Abraham | 50d8260 | 2009-12-04 05:06:38 -0300 | [diff] [blame] | 205 | |
| 206 | kfree(ca); |
| 207 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 208 | EXPORT_SYMBOL_GPL(mantis_ca_exit); |