Commit | Line | Data |
---|---|---|
50d82602 MA |
1 | /* |
2 | Mantis PCI bridge driver | |
3 | ||
8825a097 | 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
50d82602 MA |
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 | ||
b3b96144 | 21 | #include <linux/signal.h> |
5a0e3ad6 | 22 | #include <linux/slab.h> |
b3b96144 MA |
23 | #include <linux/sched.h> |
24 | #include <linux/interrupt.h> | |
b7f080cf | 25 | #include <asm/io.h> |
b3b96144 MA |
26 | |
27 | #include "dmxdev.h" | |
28 | #include "dvbdev.h" | |
29 | #include "dvb_demux.h" | |
30 | #include "dvb_frontend.h" | |
31 | #include "dvb_net.h" | |
32 | ||
50d82602 MA |
33 | #include "mantis_common.h" |
34 | #include "mantis_link.h" | |
35 | #include "mantis_hif.h" | |
b3b96144 MA |
36 | #include "mantis_reg.h" |
37 | ||
38 | #include "mantis_ca.h" | |
50d82602 | 39 | |
6053240f | 40 | static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr) |
50d82602 | 41 | { |
6053240f | 42 | struct mantis_ca *ca = en50221->data; |
2133ffbf MA |
43 | struct mantis_pci *mantis = ca->ca_priv; |
44 | ||
b3b96144 | 45 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot); |
6053240f MA |
46 | |
47 | if (slot != 0) | |
48 | return -EINVAL; | |
49 | ||
50 | return mantis_hif_read_mem(ca, addr); | |
50d82602 MA |
51 | } |
52 | ||
6053240f | 53 | static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data) |
50d82602 | 54 | { |
6053240f | 55 | struct mantis_ca *ca = en50221->data; |
2133ffbf MA |
56 | struct mantis_pci *mantis = ca->ca_priv; |
57 | ||
b3b96144 | 58 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot); |
6053240f MA |
59 | |
60 | if (slot != 0) | |
61 | return -EINVAL; | |
62 | ||
63 | return mantis_hif_write_mem(ca, addr, data); | |
50d82602 MA |
64 | } |
65 | ||
6053240f | 66 | static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr) |
50d82602 | 67 | { |
6053240f | 68 | struct mantis_ca *ca = en50221->data; |
2133ffbf MA |
69 | struct mantis_pci *mantis = ca->ca_priv; |
70 | ||
b3b96144 | 71 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot); |
6053240f MA |
72 | |
73 | if (slot != 0) | |
74 | return -EINVAL; | |
75 | ||
76 | return mantis_hif_read_iom(ca, addr); | |
50d82602 MA |
77 | } |
78 | ||
6053240f | 79 | static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data) |
50d82602 | 80 | { |
6053240f | 81 | struct mantis_ca *ca = en50221->data; |
2133ffbf MA |
82 | struct mantis_pci *mantis = ca->ca_priv; |
83 | ||
b3b96144 | 84 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot); |
50d82602 | 85 | |
6053240f MA |
86 | if (slot != 0) |
87 | return -EINVAL; | |
50d82602 | 88 | |
6053240f | 89 | return mantis_hif_write_iom(ca, addr, data); |
50d82602 MA |
90 | } |
91 | ||
6053240f | 92 | static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot) |
50d82602 | 93 | { |
2133ffbf MA |
94 | struct mantis_ca *ca = en50221->data; |
95 | struct mantis_pci *mantis = ca->ca_priv; | |
96 | ||
b3b96144 | 97 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot); |
fb6de9c5 MA |
98 | udelay(500); /* Wait.. */ |
99 | mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */ | |
100 | udelay(500); | |
101 | mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */ | |
102 | msleep(1000); | |
2ec9b00b | 103 | dvb_ca_en50221_camready_irq(&ca->en50221, 0); |
2133ffbf | 104 | |
6053240f MA |
105 | return 0; |
106 | } | |
50d82602 | 107 | |
6053240f MA |
108 | static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot) |
109 | { | |
2133ffbf MA |
110 | struct mantis_ca *ca = en50221->data; |
111 | struct mantis_pci *mantis = ca->ca_priv; | |
112 | ||
b3b96144 | 113 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot); |
2133ffbf | 114 | |
6053240f MA |
115 | return 0; |
116 | } | |
50d82602 | 117 | |
6053240f MA |
118 | static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot) |
119 | { | |
2133ffbf MA |
120 | struct mantis_ca *ca = en50221->data; |
121 | struct mantis_pci *mantis = ca->ca_priv; | |
122 | ||
b3b96144 | 123 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot); |
f5ae4f6f | 124 | /* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */ |
2133ffbf | 125 | |
50d82602 | 126 | return 0; |
50d82602 MA |
127 | } |
128 | ||
6053240f | 129 | static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open) |
50d82602 | 130 | { |
4e9fbeee | 131 | struct mantis_ca *ca = en50221->data; |
2133ffbf MA |
132 | struct mantis_pci *mantis = ca->ca_priv; |
133 | ||
b3b96144 | 134 | dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot); |
4e9fbeee | 135 | |
5e2a0c99 | 136 | if (ca->slot_state == MODULE_INSERTED) { |
b3b96144 | 137 | dprintk(MANTIS_DEBUG, 1, "CA Module present and ready"); |
4e9fbeee | 138 | return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY; |
5e2a0c99 | 139 | } else { |
b3b96144 | 140 | dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready"); |
5e2a0c99 | 141 | } |
4e9fbeee | 142 | |
6053240f MA |
143 | return 0; |
144 | } | |
50d82602 | 145 | |
6053240f MA |
146 | int mantis_ca_init(struct mantis_pci *mantis) |
147 | { | |
b3b96144 | 148 | struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter; |
50d82602 | 149 | struct mantis_ca *ca; |
6053240f | 150 | int ca_flags = 0, result; |
50d82602 | 151 | |
b3b96144 | 152 | dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA"); |
f5ae4f6f | 153 | ca = kzalloc(sizeof(struct mantis_ca), GFP_KERNEL); |
b3b96144 MA |
154 | if (!ca) { |
155 | dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting .."); | |
6053240f MA |
156 | result = -ENOMEM; |
157 | goto err; | |
50d82602 MA |
158 | } |
159 | ||
b3b96144 MA |
160 | ca->ca_priv = mantis; |
161 | mantis->mantis_ca = ca; | |
162 | ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE; | |
6053240f MA |
163 | /* register CA interface */ |
164 | ca->en50221.owner = THIS_MODULE; | |
165 | ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem; | |
166 | ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem; | |
167 | ca->en50221.read_cam_control = mantis_ca_read_cam_ctl; | |
168 | ca->en50221.write_cam_control = mantis_ca_write_cam_ctl; | |
169 | ca->en50221.slot_reset = mantis_ca_slot_reset; | |
170 | ca->en50221.slot_shutdown = mantis_ca_slot_shutdown; | |
171 | ca->en50221.slot_ts_enable = mantis_ts_control; | |
172 | ca->en50221.poll_slot_status = mantis_slot_status; | |
173 | ca->en50221.data = ca; | |
174 | ||
99b55b2c MA |
175 | mutex_init(&ca->ca_lock); |
176 | ||
42f541bf MA |
177 | init_waitqueue_head(&ca->hif_data_wq); |
178 | init_waitqueue_head(&ca->hif_opdone_wq); | |
179 | init_waitqueue_head(&ca->hif_write_wq); | |
180 | ||
b3b96144 MA |
181 | dprintk(MANTIS_ERROR, 1, "Registering EN50221 device"); |
182 | result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1); | |
183 | if (result != 0) { | |
184 | dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result); | |
6053240f | 185 | goto err; |
50d82602 | 186 | } |
b3b96144 | 187 | dprintk(MANTIS_ERROR, 1, "Registered EN50221 device"); |
6053240f | 188 | mantis_evmgr_init(ca); |
50d82602 | 189 | return 0; |
6053240f MA |
190 | err: |
191 | kfree(ca); | |
192 | return result; | |
50d82602 | 193 | } |
b3b96144 | 194 | EXPORT_SYMBOL_GPL(mantis_ca_init); |
50d82602 MA |
195 | |
196 | void mantis_ca_exit(struct mantis_pci *mantis) | |
197 | { | |
198 | struct mantis_ca *ca = mantis->mantis_ca; | |
2133ffbf | 199 | |
b3b96144 | 200 | dprintk(MANTIS_DEBUG, 1, "Mantis CA exit"); |
1d6ca29d DC |
201 | if (!ca) |
202 | return; | |
50d82602 MA |
203 | |
204 | mantis_evmgr_exit(ca); | |
b3b96144 | 205 | dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device"); |
1d6ca29d | 206 | dvb_ca_en50221_release(&ca->en50221); |
50d82602 MA |
207 | |
208 | kfree(ca); | |
209 | } | |
b3b96144 | 210 | EXPORT_SYMBOL_GPL(mantis_ca_exit); |