⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 budget-ci.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * budget-ci.c: driver for the SAA7146 based Budget DVB cards * * Compiled from various sources by Michael Hunold <michael@mihu.de> * *     msp430 IR support contributed by Jack Thomasson <jkt@Helius.COM> *     partially based on the Siemens DVB driver by Ralph+Marcus Metzler * * CI interface support (c) 2004 Andrew de Quincey <adq_dvb@lidskialf.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html * * * the project's page is at http://www.linuxtv.org/dvb/ */#include <linux/module.h>#include <linux/errno.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/input.h>#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23)/* Fix compile warning */#undef BIT#endif#include <linux/spinlock.h>#include <media/ir-common.h>#include "budget.h"#include "dvb_ca_en50221.h"#include "stv0299.h"#include "stv0297.h"#include "tda1004x.h"#include "lnbp21.h"#include "bsbe1.h"#include "bsru6.h"#include "tda1002x.h"#include "tda827x.h"/* * Regarding DEBIADDR_IR: * Some CI modules hang if random addresses are read. * Using address 0x4000 for the IR read means that we * use the same address as for CI version, which should * be a safe default. */#define DEBIADDR_IR		0x4000#define DEBIADDR_CICONTROL	0x0000#define DEBIADDR_CIVERSION	0x4000#define DEBIADDR_IO		0x1000#define DEBIADDR_ATTR		0x3000#define CICONTROL_RESET		0x01#define CICONTROL_ENABLETS	0x02#define CICONTROL_CAMDETECT	0x08#define DEBICICTL		0x00420000#define DEBICICAM		0x02420000#define SLOTSTATUS_NONE		1#define SLOTSTATUS_PRESENT	2#define SLOTSTATUS_RESET	4#define SLOTSTATUS_READY	8#define SLOTSTATUS_OCCUPIED	(SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)/* * Milliseconds during which a key is regarded as pressed. * If an identical command arrives within this time, the timer will start over. */#define IR_KEYPRESS_TIMEOUT	250/* RC5 device wildcard */#define IR_DEVICE_ANY		255static int rc5_device = -1;module_param(rc5_device, int, 0644);MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");static int ir_debug;module_param(ir_debug, int, 0644);MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);struct budget_ci_ir {	struct input_dev *dev;	struct tasklet_struct msp430_irq_tasklet;	struct timer_list timer_keyup;	char name[72]; /* 40 + 32 for (struct saa7146_dev).name */	char phys[32];	struct ir_input_state state;	int rc5_device;	u32 last_raw;	u32 ir_key;	bool have_command;};struct budget_ci {	struct budget budget;	struct tasklet_struct ciintf_irq_tasklet;	int slot_status;	int ci_irq;	struct dvb_ca_en50221 ca;	struct budget_ci_ir ir;	u8 tuner_pll_address; /* used for philips_tdm1316l configs */};static void msp430_ir_keyup(unsigned long data){	struct budget_ci_ir *ir = (struct budget_ci_ir *) data;	ir_input_nokey(ir->dev, &ir->state);}static void msp430_ir_interrupt(unsigned long data){	struct budget_ci *budget_ci = (struct budget_ci *) data;	struct input_dev *dev = budget_ci->ir.dev;	u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;	u32 raw;	/*	 * The msp430 chip can generate two different bytes, command and device	 *	 * type1: X1CCCCCC, C = command bits (0 - 63)	 * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit	 *	 * Each signal from the remote control can generate one or more command	 * bytes and one or more device bytes. For the repeated bytes, the	 * highest bit (X) is set. The first command byte is always generated	 * before the first device byte. Other than that, no specific order	 * seems to apply. To make life interesting, bytes can also be lost.	 *	 * Only when we have a command and device byte, a keypress is	 * generated.	 */	if (ir_debug)		printk("budget_ci: received byte 0x%02x\n", command);	/* Remove repeat bit, we use every command */	command = command & 0x7f;	/* Is this a RC5 command byte? */	if (command & 0x40) {		budget_ci->ir.have_command = true;		budget_ci->ir.ir_key = command & 0x3f;		return;	}	/* It's a RC5 device byte */	if (!budget_ci->ir.have_command)		return;	budget_ci->ir.have_command = false;	if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&	    budget_ci->ir.rc5_device != (command & 0x1f))		return;	/* Is this a repeated key sequence? (same device, command, toggle) */	raw = budget_ci->ir.ir_key | (command << 8);	if (budget_ci->ir.last_raw != raw || !timer_pending(&budget_ci->ir.timer_keyup)) {		ir_input_nokey(dev, &budget_ci->ir.state);		ir_input_keydown(dev, &budget_ci->ir.state,				 budget_ci->ir.ir_key, raw);		budget_ci->ir.last_raw = raw;	}	mod_timer(&budget_ci->ir.timer_keyup, jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT));}static int msp430_ir_init(struct budget_ci *budget_ci){	struct saa7146_dev *saa = budget_ci->budget.dev;	struct input_dev *input_dev = budget_ci->ir.dev;	int error;	budget_ci->ir.dev = input_dev = input_allocate_device();	if (!input_dev) {		printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");		error = -ENOMEM;		goto out1;	}	snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),		 "Budget-CI dvb ir receiver %s", saa->name);	snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),		 "pci-%s/ir0", pci_name(saa->pci));	input_dev->name = budget_ci->ir.name;	input_dev->phys = budget_ci->ir.phys;	input_dev->id.bustype = BUS_PCI;	input_dev->id.version = 1;	if (saa->pci->subsystem_vendor) {		input_dev->id.vendor = saa->pci->subsystem_vendor;		input_dev->id.product = saa->pci->subsystem_device;	} else {		input_dev->id.vendor = saa->pci->vendor;		input_dev->id.product = saa->pci->device;	}#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)	input_dev->dev.parent = &saa->pci->dev;#else	input_dev->cdev.dev = &saa->pci->dev;#endif	/* Select keymap and address */	switch (budget_ci->budget.dev->pci->subsystem_device) {	case 0x100c:	case 0x100f:	case 0x1011:	case 0x1012:		/* The hauppauge keymap is a superset of these remotes */		ir_input_init(input_dev, &budget_ci->ir.state,			      IR_TYPE_RC5, ir_codes_hauppauge_new);		if (rc5_device < 0)			budget_ci->ir.rc5_device = 0x1f;		else			budget_ci->ir.rc5_device = rc5_device;		break;	case 0x1010:	case 0x1017:	case 0x101a:		/* for the Technotrend 1500 bundled remote */		ir_input_init(input_dev, &budget_ci->ir.state,			      IR_TYPE_RC5, ir_codes_tt_1500);		if (rc5_device < 0)			budget_ci->ir.rc5_device = IR_DEVICE_ANY;		else			budget_ci->ir.rc5_device = rc5_device;		break;	default:		/* unknown remote */		ir_input_init(input_dev, &budget_ci->ir.state,			      IR_TYPE_RC5, ir_codes_budget_ci_old);		if (rc5_device < 0)			budget_ci->ir.rc5_device = IR_DEVICE_ANY;		else			budget_ci->ir.rc5_device = rc5_device;		break;	}	/* initialise the key-up timeout handler */	init_timer(&budget_ci->ir.timer_keyup);	budget_ci->ir.timer_keyup.function = msp430_ir_keyup;	budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;	budget_ci->ir.last_raw = 0xffff; /* An impossible value */	error = input_register_device(input_dev);	if (error) {		printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);		goto out2;	}	/* note: these must be after input_register_device */	input_dev->rep[REP_DELAY] = 400;	input_dev->rep[REP_PERIOD] = 250;	tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,		     (unsigned long) budget_ci);	SAA7146_IER_ENABLE(saa, MASK_06);	saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);	return 0;out2:	input_free_device(input_dev);out1:	return error;}static void msp430_ir_deinit(struct budget_ci *budget_ci){	struct saa7146_dev *saa = budget_ci->budget.dev;	struct input_dev *dev = budget_ci->ir.dev;	SAA7146_IER_DISABLE(saa, MASK_06);	saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);	tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);	del_timer_sync(&dev->timer);	ir_input_nokey(dev, &budget_ci->ir.state);	input_unregister_device(dev);}static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	if (slot != 0)		return -EINVAL;	return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,				     DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);}static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	if (slot != 0)		return -EINVAL;	return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,				      DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);}static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	if (slot != 0)		return -EINVAL;	return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,				     DEBIADDR_IO | (address & 3), 1, 1, 0);}static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	if (slot != 0)		return -EINVAL;	return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,				      DEBIADDR_IO | (address & 3), 1, value, 1, 0);}static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	struct saa7146_dev *saa = budget_ci->budget.dev;	if (slot != 0)		return -EINVAL;	if (budget_ci->ci_irq) {		// trigger on RISING edge during reset so we know when READY is re-asserted		saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);	}	budget_ci->slot_status = SLOTSTATUS_RESET;	ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);	msleep(1);	ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,			       CICONTROL_RESET, 1, 0);	saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);	ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);	return 0;}static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	struct saa7146_dev *saa = budget_ci->budget.dev;	if (slot != 0)		return -EINVAL;	saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);	ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);	return 0;}static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot){	struct budget_ci *budget_ci = (struct budget_ci *) ca->data;	struct saa7146_dev *saa = budget_ci->budget.dev;	int tmp;	if (slot != 0)		return -EINVAL;	saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);	tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);	ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,			       tmp | CICONTROL_ENABLETS, 1, 0);	ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);	return 0;}static void ciintf_interrupt(unsigned long data){	struct budget_ci *budget_ci = (struct budget_ci *) data;	struct saa7146_dev *saa = budget_ci->budget.dev;	unsigned int flags;	// ensure we don't get spurious IRQs during initialisation	if (!budget_ci->budget.ci_present)		return;	// read the CAM status	flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);	if (flags & CICONTROL_CAMDETECT) {		// GPIO should be set to trigger on falling edge if a CAM is present		saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);		if (budget_ci->slot_status & SLOTSTATUS_NONE) {			// CAM insertion IRQ			budget_ci->slot_status = SLOTSTATUS_PRESENT;			dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,						     DVB_CA_EN50221_CAMCHANGE_INSERTED);		} else if (budget_ci->slot_status & SLOTSTATUS_RESET) {			// CAM ready (reset completed)			budget_ci->slot_status = SLOTSTATUS_READY;			dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);		} else if (budget_ci->slot_status & SLOTSTATUS_READY) {			// FR/DA IRQ

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -