blob: f2baf5e5c9218738acbe9e0db9d6dadc0af270f8 [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Manu Abraham50d82602009-12-04 05:06:38 -03002/*
3 Mantis PCI bridge driver
4
Manu Abraham8825a092009-12-15 09:13:49 -03005 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
Manu Abraham50d82602009-12-04 05:06:38 -03006
Manu Abraham50d82602009-12-04 05:06:38 -03007*/
8
Manu Abrahamb3b96142009-12-04 05:41:11 -03009#include <linux/signal.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Manu Abrahamb3b96142009-12-04 05:41:11 -030011#include <linux/sched.h>
12#include <linux/interrupt.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000013#include <asm/io.h>
Manu Abrahamb3b96142009-12-04 05:41:11 -030014
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050015#include <media/dmxdev.h>
16#include <media/dvbdev.h>
17#include <media/dvb_demux.h>
18#include <media/dvb_frontend.h>
19#include <media/dvb_net.h>
Manu Abrahamb3b96142009-12-04 05:41:11 -030020
Manu Abraham50d82602009-12-04 05:06:38 -030021#include "mantis_common.h"
22#include "mantis_link.h"
23#include "mantis_hif.h"
Manu Abrahamb3b96142009-12-04 05:41:11 -030024#include "mantis_reg.h"
25
26#include "mantis_ca.h"
Manu Abraham50d82602009-12-04 05:06:38 -030027
Manu Abraham60532402009-12-04 05:11:14 -030028static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr)
29{
30 struct mantis_ca *ca = en50221->data;
Manu Abraham2133ffb2009-12-04 05:12:16 -030031 struct mantis_pci *mantis = ca->ca_priv;
32
Manu Abrahamb3b96142009-12-04 05:41:11 -030033 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot);
Manu Abraham50d82602009-12-04 05:06:38 -030034
Manu Abraham60532402009-12-04 05:11:14 -030035 if (slot != 0)
36 return -EINVAL;
37
38 return mantis_hif_read_mem(ca, addr);
39}
40
41static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data)
42{
43 struct mantis_ca *ca = en50221->data;
Manu Abraham2133ffb2009-12-04 05:12:16 -030044 struct mantis_pci *mantis = ca->ca_priv;
45
Manu Abrahamb3b96142009-12-04 05:41:11 -030046 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot);
Manu Abraham60532402009-12-04 05:11:14 -030047
48 if (slot != 0)
49 return -EINVAL;
50
51 return mantis_hif_write_mem(ca, addr, data);
52}
53
54static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr)
55{
56 struct mantis_ca *ca = en50221->data;
Manu Abraham2133ffb2009-12-04 05:12:16 -030057 struct mantis_pci *mantis = ca->ca_priv;
58
Manu Abrahamb3b96142009-12-04 05:41:11 -030059 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot);
Manu Abraham60532402009-12-04 05:11:14 -030060
61 if (slot != 0)
62 return -EINVAL;
63
64 return mantis_hif_read_iom(ca, addr);
65}
66
67static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data)
68{
69 struct mantis_ca *ca = en50221->data;
Manu Abraham2133ffb2009-12-04 05:12:16 -030070 struct mantis_pci *mantis = ca->ca_priv;
71
Manu Abrahamb3b96142009-12-04 05:41:11 -030072 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot);
Manu Abraham60532402009-12-04 05:11:14 -030073
74 if (slot != 0)
75 return -EINVAL;
76
77 return mantis_hif_write_iom(ca, addr, data);
78}
79
80static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
Manu Abraham50d82602009-12-04 05:06:38 -030081{
Manu Abraham2133ffb2009-12-04 05:12:16 -030082 struct mantis_ca *ca = en50221->data;
83 struct mantis_pci *mantis = ca->ca_priv;
84
Manu Abrahamb3b96142009-12-04 05:41:11 -030085 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot);
Manu Abrahamfb6de9c2009-12-04 05:17:46 -030086 udelay(500); /* Wait.. */
87 mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */
88 udelay(500);
89 mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */
90 msleep(1000);
Manu Abraham2ec9b002009-12-04 05:20:44 -030091 dvb_ca_en50221_camready_irq(&ca->en50221, 0);
Manu Abraham2133ffb2009-12-04 05:12:16 -030092
Manu Abraham50d82602009-12-04 05:06:38 -030093 return 0;
94}
95
Manu Abraham60532402009-12-04 05:11:14 -030096static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
Manu Abraham50d82602009-12-04 05:06:38 -030097{
Manu Abraham2133ffb2009-12-04 05:12:16 -030098 struct mantis_ca *ca = en50221->data;
99 struct mantis_pci *mantis = ca->ca_priv;
100
Manu Abrahamb3b96142009-12-04 05:41:11 -0300101 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot);
Manu Abraham2133ffb2009-12-04 05:12:16 -0300102
Manu Abraham50d82602009-12-04 05:06:38 -0300103 return 0;
104}
105
Manu Abraham60532402009-12-04 05:11:14 -0300106static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot)
Manu Abraham50d82602009-12-04 05:06:38 -0300107{
Manu Abraham2133ffb2009-12-04 05:12:16 -0300108 struct mantis_ca *ca = en50221->data;
109 struct mantis_pci *mantis = ca->ca_priv;
110
Manu Abrahamb3b96142009-12-04 05:41:11 -0300111 dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot);
Manu Abrahamf5ae4f62009-12-15 08:47:21 -0300112/* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */
Manu Abraham2133ffb2009-12-04 05:12:16 -0300113
Manu Abraham50d82602009-12-04 05:06:38 -0300114 return 0;
115}
116
Manu Abraham60532402009-12-04 05:11:14 -0300117static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open)
Manu Abraham50d82602009-12-04 05:06:38 -0300118{
Manu Abraham4e9fbee2009-12-04 05:11:41 -0300119 struct mantis_ca *ca = en50221->data;
Manu Abraham2133ffb2009-12-04 05:12:16 -0300120 struct mantis_pci *mantis = ca->ca_priv;
121
Manu Abrahamb3b96142009-12-04 05:41:11 -0300122 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot);
Manu Abraham4e9fbee2009-12-04 05:11:41 -0300123
Manu Abraham5e2a0c92009-12-04 05:23:17 -0300124 if (ca->slot_state == MODULE_INSERTED) {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300125 dprintk(MANTIS_DEBUG, 1, "CA Module present and ready");
Manu Abraham4e9fbee2009-12-04 05:11:41 -0300126 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
Manu Abraham5e2a0c92009-12-04 05:23:17 -0300127 } else {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300128 dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready");
Manu Abraham5e2a0c92009-12-04 05:23:17 -0300129 }
Manu Abraham4e9fbee2009-12-04 05:11:41 -0300130
Manu Abraham50d82602009-12-04 05:06:38 -0300131 return 0;
Manu Abraham50d82602009-12-04 05:06:38 -0300132}
133
Manu Abraham60532402009-12-04 05:11:14 -0300134int mantis_ca_init(struct mantis_pci *mantis)
Manu Abraham50d82602009-12-04 05:06:38 -0300135{
Manu Abrahamb3b96142009-12-04 05:41:11 -0300136 struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter;
Manu Abraham50d82602009-12-04 05:06:38 -0300137 struct mantis_ca *ca;
Manu Abraham60532402009-12-04 05:11:14 -0300138 int ca_flags = 0, result;
Manu Abraham50d82602009-12-04 05:06:38 -0300139
Manu Abrahamb3b96142009-12-04 05:41:11 -0300140 dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA");
Manu Abrahamf5ae4f62009-12-15 08:47:21 -0300141 ca = kzalloc(sizeof(struct mantis_ca), GFP_KERNEL);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300142 if (!ca) {
143 dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting ..");
Manu Abraham60532402009-12-04 05:11:14 -0300144 result = -ENOMEM;
145 goto err;
Manu Abraham50d82602009-12-04 05:06:38 -0300146 }
147
Manu Abrahamb3b96142009-12-04 05:41:11 -0300148 ca->ca_priv = mantis;
149 mantis->mantis_ca = ca;
150 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE;
Manu Abraham60532402009-12-04 05:11:14 -0300151 /* register CA interface */
152 ca->en50221.owner = THIS_MODULE;
153 ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem;
154 ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem;
155 ca->en50221.read_cam_control = mantis_ca_read_cam_ctl;
156 ca->en50221.write_cam_control = mantis_ca_write_cam_ctl;
157 ca->en50221.slot_reset = mantis_ca_slot_reset;
158 ca->en50221.slot_shutdown = mantis_ca_slot_shutdown;
159 ca->en50221.slot_ts_enable = mantis_ts_control;
160 ca->en50221.poll_slot_status = mantis_slot_status;
161 ca->en50221.data = ca;
162
Manu Abraham99b55b22009-12-04 05:34:44 -0300163 mutex_init(&ca->ca_lock);
164
Manu Abraham42f541b2009-12-04 05:35:07 -0300165 init_waitqueue_head(&ca->hif_data_wq);
166 init_waitqueue_head(&ca->hif_opdone_wq);
167 init_waitqueue_head(&ca->hif_write_wq);
168
Manu Abrahamb3b96142009-12-04 05:41:11 -0300169 dprintk(MANTIS_ERROR, 1, "Registering EN50221 device");
170 result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1);
171 if (result != 0) {
172 dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result);
Manu Abraham60532402009-12-04 05:11:14 -0300173 goto err;
Manu Abraham50d82602009-12-04 05:06:38 -0300174 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300175 dprintk(MANTIS_ERROR, 1, "Registered EN50221 device");
Manu Abraham60532402009-12-04 05:11:14 -0300176 mantis_evmgr_init(ca);
Manu Abraham50d82602009-12-04 05:06:38 -0300177 return 0;
Manu Abraham60532402009-12-04 05:11:14 -0300178err:
179 kfree(ca);
180 return result;
Manu Abraham50d82602009-12-04 05:06:38 -0300181}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300182EXPORT_SYMBOL_GPL(mantis_ca_init);
Manu Abraham50d82602009-12-04 05:06:38 -0300183
184void mantis_ca_exit(struct mantis_pci *mantis)
185{
186 struct mantis_ca *ca = mantis->mantis_ca;
Manu Abraham2133ffb2009-12-04 05:12:16 -0300187
Manu Abrahamb3b96142009-12-04 05:41:11 -0300188 dprintk(MANTIS_DEBUG, 1, "Mantis CA exit");
Dan Carpenter1d6ca292012-12-02 06:43:13 -0300189 if (!ca)
190 return;
Manu Abraham50d82602009-12-04 05:06:38 -0300191
192 mantis_evmgr_exit(ca);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300193 dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device");
Dan Carpenter1d6ca292012-12-02 06:43:13 -0300194 dvb_ca_en50221_release(&ca->en50221);
Manu Abraham50d82602009-12-04 05:06:38 -0300195
196 kfree(ca);
197}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300198EXPORT_SYMBOL_GPL(mantis_ca_exit);