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

📄 cxusb.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
/* DVB USB compliant linux driver for Conexant USB reference design. * * The Conexant reference design I saw on their website was only for analogue * capturing (using the cx25842). The box I took to write this driver (reverse * engineered) is the one labeled Medion MD95700. In addition to the cx25842 * for analogue capturing it also has a cx22702 DVB-T demodulator on the main * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard. * * Maybe it is a little bit premature to call this driver cxusb, but I assume * the USB protocol is identical or at least inherited from the reference * design, so it can be reused for the "analogue-only" device (if it will * appear at all). * * TODO: Use the cx25840-driver for the analogue part * * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org) * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au) * *   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, version 2. * * see Documentation/dvb/README.dvb-usb for more information */#include <media/tuner.h>#include <linux/vmalloc.h>#include "cxusb.h"#include "cx22702.h"#include "lgdt330x.h"#include "mt352.h"#include "mt352_priv.h"#include "zl10353.h"#include "tuner-xc2028.h"#include "tuner-simple.h"#include "mxl5005s.h"#include "dib7000p.h"#include "dib0070.h"#include "lgs8gl5.h"/* debug */static int dvb_usb_cxusb_debug;module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);#define deb_info(args...)   dprintk(dvb_usb_cxusb_debug, 0x03, args)#define deb_i2c(args...)    dprintk(dvb_usb_cxusb_debug, 0x02, args)static int cxusb_ctrl_msg(struct dvb_usb_device *d,			  u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen){	int wo = (rbuf == NULL || rlen == 0); /* write-only */	u8 sndbuf[1+wlen];	memset(sndbuf, 0, 1+wlen);	sndbuf[0] = cmd;	memcpy(&sndbuf[1], wbuf, wlen);	if (wo)		return dvb_usb_generic_write(d, sndbuf, 1+wlen);	else		return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);}/* GPIO */static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff){	struct cxusb_state *st = d->priv;	u8 o[2], i;	if (st->gpio_write_state[GPIO_TUNER] == onoff)		return;	o[0] = GPIO_TUNER;	o[1] = onoff;	cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);	if (i != 0x01)		deb_info("gpio_write failed.\n");	st->gpio_write_state[GPIO_TUNER] = onoff;}static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,				 u8 newval){	u8 o[2], gpio_state;	int rc;	o[0] = 0xff & ~changemask;	/* mask of bits to keep */	o[1] = newval & changemask;	/* new values for bits  */	rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);	if (rc < 0 || (gpio_state & changemask) != (newval & changemask))		deb_info("bluebird_gpio_write failed.\n");	return rc < 0 ? rc : gpio_state;}static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low){	cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);	msleep(5);	cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);}static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff){	cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);}static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,		u8 addr, int onoff){	u8  o[2] = {addr, onoff};	u8  i;	int rc;	rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);	if (rc < 0)		return rc;	if (i == 0x01)		return 0;	else {		deb_info("gpio_write failed.\n");		return -EIO;	}}/* I2C */static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],			  int num){	struct dvb_usb_device *d = i2c_get_adapdata(adap);	int i;	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)		return -EAGAIN;	for (i = 0; i < num; i++) {		if (d->udev->descriptor.idVendor == USB_VID_MEDION)			switch (msg[i].addr) {			case 0x63:				cxusb_gpio_tuner(d, 0);				break;			default:				cxusb_gpio_tuner(d, 1);				break;			}		if (msg[i].flags & I2C_M_RD) {			/* read only */			u8 obuf[3], ibuf[1+msg[i].len];			obuf[0] = 0;			obuf[1] = msg[i].len;			obuf[2] = msg[i].addr;			if (cxusb_ctrl_msg(d, CMD_I2C_READ,					   obuf, 3,					   ibuf, 1+msg[i].len) < 0) {				warn("i2c read failed");				break;			}			memcpy(msg[i].buf, &ibuf[1], msg[i].len);		} else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&			   msg[i].addr == msg[i+1].addr) {			/* write to then read from same address */			u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];			obuf[0] = msg[i].len;			obuf[1] = msg[i+1].len;			obuf[2] = msg[i].addr;			memcpy(&obuf[3], msg[i].buf, msg[i].len);			if (cxusb_ctrl_msg(d, CMD_I2C_READ,					   obuf, 3+msg[i].len,					   ibuf, 1+msg[i+1].len) < 0)				break;			if (ibuf[0] != 0x08)				deb_i2c("i2c read may have failed\n");			memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);			i++;		} else {			/* write only */			u8 obuf[2+msg[i].len], ibuf;			obuf[0] = msg[i].addr;			obuf[1] = msg[i].len;			memcpy(&obuf[2], msg[i].buf, msg[i].len);			if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,					   2+msg[i].len, &ibuf,1) < 0)				break;			if (ibuf != 0x08)				deb_i2c("i2c write may have failed\n");		}	}	mutex_unlock(&d->i2c_mutex);	return i == num ? num : -EREMOTEIO;}static u32 cxusb_i2c_func(struct i2c_adapter *adapter){	return I2C_FUNC_I2C;}static struct i2c_algorithm cxusb_i2c_algo = {	.master_xfer   = cxusb_i2c_xfer,	.functionality = cxusb_i2c_func,};static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff){	u8 b = 0;	if (onoff)		return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);	else		return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);}static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff){	int ret;	if (!onoff)		return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);	if (d->state == DVB_USB_STATE_INIT &&	    usb_set_interface(d->udev, 0, 0) < 0)		err("set interface failed");	do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&		   !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&		   !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);	if (!ret) {		/* FIXME: We don't know why, but we need to configure the		 * lgdt3303 with the register settings below on resume */		int i;		u8 buf, bufs[] = {			0x0e, 0x2, 0x00, 0x7f,			0x0e, 0x2, 0x02, 0xfe,			0x0e, 0x2, 0x02, 0x01,			0x0e, 0x2, 0x00, 0x03,			0x0e, 0x2, 0x0d, 0x40,			0x0e, 0x2, 0x0e, 0x87,			0x0e, 0x2, 0x0f, 0x8e,			0x0e, 0x2, 0x10, 0x01,			0x0e, 0x2, 0x14, 0xd7,			0x0e, 0x2, 0x47, 0x88,		};		msleep(20);		for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {			ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,					     bufs+i, 4, &buf, 1);			if (ret)				break;			if (buf != 0x8)				return -EREMOTEIO;		}	}	return ret;}static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff){	u8 b = 0;	if (onoff)		return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);	else		return 0;}static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff){	int rc = 0;	rc = cxusb_power_ctrl(d, onoff);	if (!onoff)		cxusb_nano2_led(d, 0);	return rc;}static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff){	int ret;	u8  b;	ret = cxusb_power_ctrl(d, onoff);	if (!onoff)		return ret;	msleep(128);	cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);	msleep(100);	return ret;}static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff){	u8 buf[2] = { 0x03, 0x00 };	if (onoff)		cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);	else		cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);	return 0;}static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff){	if (onoff)		cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);	else		cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,			       NULL, 0, NULL, 0);	return 0;}static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d){	int       ep = d->props.generic_bulk_ctrl_endpoint;	const int timeout = 100;	const int junk_len = 32;	u8        *junk;	int       rd_count;	/* Discard remaining data in video pipe */	junk = kmalloc(junk_len, GFP_KERNEL);	if (!junk)		return;	while (1) {		if (usb_bulk_msg(d->udev,			usb_rcvbulkpipe(d->udev, ep),			junk, junk_len, &rd_count, timeout) < 0)			break;		if (!rd_count)			break;	}	kfree(junk);}static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d){	struct usb_data_stream_properties *p = &d->props.adapter[0].stream;	const int timeout = 100;	const int junk_len = p->u.bulk.buffersize;	u8        *junk;	int       rd_count;	/* Discard remaining data in video pipe */	junk = kmalloc(junk_len, GFP_KERNEL);	if (!junk)		return;	while (1) {		if (usb_bulk_msg(d->udev,			usb_rcvbulkpipe(d->udev, p->endpoint),			junk, junk_len, &rd_count, timeout) < 0)			break;		if (!rd_count)			break;	}	kfree(junk);}static int cxusb_d680_dmb_streaming_ctrl(		struct dvb_usb_adapter *adap, int onoff){	if (onoff) {		u8 buf[2] = { 0x03, 0x00 };		cxusb_d680_dmb_drain_video(adap->dev);		return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,			buf, sizeof(buf), NULL, 0);	} else {		int ret = cxusb_ctrl_msg(adap->dev,			CMD_STREAMING_OFF, NULL, 0, NULL, 0);		return ret;	}}static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state){	struct dvb_usb_rc_key *keymap = d->props.rc_key_map;	u8 ircode[4];	int i;	cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);	*event = 0;	*state = REMOTE_NO_KEY_PRESSED;	for (i = 0; i < d->props.rc_key_map_size; i++) {		if (keymap[i].custom == ircode[2] &&		    keymap[i].data == ircode[3]) {			*event = keymap[i].event;			*state = REMOTE_KEY_PRESSED;			return 0;		}	}	return 0;}static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,				    int *state){	struct dvb_usb_rc_key *keymap = d->props.rc_key_map;	u8 ircode[4];	int i;	struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,			       .buf = ircode, .len = 4 };	*event = 0;	*state = REMOTE_NO_KEY_PRESSED;	if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)		return 0;	for (i = 0; i < d->props.rc_key_map_size; i++) {		if (keymap[i].custom == ircode[1] &&		    keymap[i].data == ircode[2]) {			*event = keymap[i].event;			*state = REMOTE_KEY_PRESSED;			return 0;		}	}	return 0;}static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,		int *state){	struct dvb_usb_rc_key *keymap = d->props.rc_key_map;	u8 ircode[2];	int i;	*event = 0;	*state = REMOTE_NO_KEY_PRESSED;	if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)		return 0;	for (i = 0; i < d->props.rc_key_map_size; i++) {		if (keymap[i].custom == ircode[0] &&		    keymap[i].data == ircode[1]) {			*event = keymap[i].event;			*state = REMOTE_KEY_PRESSED;			return 0;		}	}	return 0;}static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {	{ 0xfe, 0x02, KEY_TV },	{ 0xfe, 0x0e, KEY_MP3 },	{ 0xfe, 0x1a, KEY_DVD },

⌨️ 快捷键说明

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