Path: blob/master/drivers/media/dvb/mantis/mantis_ca.c
15112 views
/*1Mantis PCI bridge driver23Copyright (C) Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/signal.h>21#include <linux/slab.h>22#include <linux/sched.h>23#include <linux/interrupt.h>2425#include "dmxdev.h"26#include "dvbdev.h"27#include "dvb_demux.h"28#include "dvb_frontend.h"29#include "dvb_net.h"3031#include "mantis_common.h"32#include "mantis_link.h"33#include "mantis_hif.h"34#include "mantis_reg.h"3536#include "mantis_ca.h"3738static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr)39{40struct mantis_ca *ca = en50221->data;41struct mantis_pci *mantis = ca->ca_priv;4243dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot);4445if (slot != 0)46return -EINVAL;4748return mantis_hif_read_mem(ca, addr);49}5051static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr, u8 data)52{53struct mantis_ca *ca = en50221->data;54struct mantis_pci *mantis = ca->ca_priv;5556dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot);5758if (slot != 0)59return -EINVAL;6061return mantis_hif_write_mem(ca, addr, data);62}6364static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr)65{66struct mantis_ca *ca = en50221->data;67struct mantis_pci *mantis = ca->ca_priv;6869dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot);7071if (slot != 0)72return -EINVAL;7374return mantis_hif_read_iom(ca, addr);75}7677static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr, u8 data)78{79struct mantis_ca *ca = en50221->data;80struct mantis_pci *mantis = ca->ca_priv;8182dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot);8384if (slot != 0)85return -EINVAL;8687return mantis_hif_write_iom(ca, addr, data);88}8990static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot)91{92struct mantis_ca *ca = en50221->data;93struct mantis_pci *mantis = ca->ca_priv;9495dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot);96udelay(500); /* Wait.. */97mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */98udelay(500);99mmwrite(0x00, MANTIS_PCMCIA_RESET); /* Trailing edge deassert */100msleep(1000);101dvb_ca_en50221_camready_irq(&ca->en50221, 0);102103return 0;104}105106static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)107{108struct mantis_ca *ca = en50221->data;109struct mantis_pci *mantis = ca->ca_priv;110111dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot);112113return 0;114}115116static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot)117{118struct mantis_ca *ca = en50221->data;119struct mantis_pci *mantis = ca->ca_priv;120121dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot);122/* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */123124return 0;125}126127static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open)128{129struct mantis_ca *ca = en50221->data;130struct mantis_pci *mantis = ca->ca_priv;131132dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot);133134if (ca->slot_state == MODULE_INSERTED) {135dprintk(MANTIS_DEBUG, 1, "CA Module present and ready");136return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;137} else {138dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready");139}140141return 0;142}143144int mantis_ca_init(struct mantis_pci *mantis)145{146struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter;147struct mantis_ca *ca;148int ca_flags = 0, result;149150dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA");151ca = kzalloc(sizeof(struct mantis_ca), GFP_KERNEL);152if (!ca) {153dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting ..");154result = -ENOMEM;155goto err;156}157158ca->ca_priv = mantis;159mantis->mantis_ca = ca;160ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE;161/* register CA interface */162ca->en50221.owner = THIS_MODULE;163ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem;164ca->en50221.write_attribute_mem = mantis_ca_write_attr_mem;165ca->en50221.read_cam_control = mantis_ca_read_cam_ctl;166ca->en50221.write_cam_control = mantis_ca_write_cam_ctl;167ca->en50221.slot_reset = mantis_ca_slot_reset;168ca->en50221.slot_shutdown = mantis_ca_slot_shutdown;169ca->en50221.slot_ts_enable = mantis_ts_control;170ca->en50221.poll_slot_status = mantis_slot_status;171ca->en50221.data = ca;172173mutex_init(&ca->ca_lock);174175init_waitqueue_head(&ca->hif_data_wq);176init_waitqueue_head(&ca->hif_opdone_wq);177init_waitqueue_head(&ca->hif_write_wq);178179dprintk(MANTIS_ERROR, 1, "Registering EN50221 device");180result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1);181if (result != 0) {182dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result);183goto err;184}185dprintk(MANTIS_ERROR, 1, "Registered EN50221 device");186mantis_evmgr_init(ca);187return 0;188err:189kfree(ca);190return result;191}192EXPORT_SYMBOL_GPL(mantis_ca_init);193194void mantis_ca_exit(struct mantis_pci *mantis)195{196struct mantis_ca *ca = mantis->mantis_ca;197198dprintk(MANTIS_DEBUG, 1, "Mantis CA exit");199200mantis_evmgr_exit(ca);201dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device");202if (ca)203dvb_ca_en50221_release(&ca->en50221);204205kfree(ca);206}207EXPORT_SYMBOL_GPL(mantis_ca_exit);208209210