📄 ivtv-driver.c
字号:
/* ivtv driver initialization and card probing Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com> Copyright (C) 2004 Chris Kennedy <c@groovy.org> Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> 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 *//* Main Driver file for the ivtv project: * Driver for the Conexant CX23415/CX23416 chip. * Author: Kevin Thayer (nufan_wfk at yahoo.com) * License: GPL * http://www.ivtvdriver.org * * ----- * MPG600/MPG160 support by T.Adachi <tadachi@tadachi-net.com> * and Takeru KOMORIYA<komoriya@paken.org> * * AVerMedia M179 GPIO info by Chris Pinkham <cpinkham@bc2va.org> * using information provided by Jiun-Kuei Jung @ AVerMedia. * * Kurouto Sikou CX23416GYC-STVLP tested by K.Ohta <alpha292@bremen.or.jp> * using information from T.Adachi,Takeru KOMORIYA and others :-) * * Nagase TRANSGEAR 5000TV, Aopen VA2000MAX-STN6 and I/O data GV-MVP/RX * version by T.Adachi. Special thanks Mr.Suzuki */#include "ivtv-driver.h"#include "ivtv-version.h"#include "ivtv-fileops.h"#include "ivtv-i2c.h"#include "ivtv-firmware.h"#include "ivtv-queue.h"#include "ivtv-udma.h"#include "ivtv-irq.h"#include "ivtv-mailbox.h"#include "ivtv-streams.h"#include "ivtv-ioctl.h"#include "ivtv-cards.h"#include "ivtv-vbi.h"#include "ivtv-routing.h"#include "ivtv-gpio.h"#include "ivtv-yuv.h"#include <media/tveeprom.h>#include <media/saa7115.h>#include <media/v4l2-chip-ident.h>/* var to keep track of the number of array elements in use */int ivtv_cards_active = 0;/* If you have already X v4l cards, then set this to X. This way the device numbers stay matched. Example: you have a WinTV card without radio and a PVR-350 with. Normally this would give a video1 device together with a radio0 device for the PVR. By setting this to 1 you ensure that radio0 is now also radio1. */int ivtv_first_minor = 0;/* Master variable for all ivtv info */struct ivtv *ivtv_cards[IVTV_MAX_CARDS];/* Protects ivtv_cards_active */DEFINE_SPINLOCK(ivtv_cards_lock);/* add your revision and whatnot here */static struct pci_device_id ivtv_pci_tbl[] __devinitdata = { {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0,}};MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);/* Parameter declarations */static int cardtype[IVTV_MAX_CARDS];static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };static int radio[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };static unsigned int cardtype_c = 1;static unsigned int tuner_c = 1;static unsigned int radio_c = 1;static char pal[] = "--";static char secam[] = "--";static char ntsc[] = "-";/* Buffers *//* DMA Buffers, Default size in MB allocated */#define IVTV_DEFAULT_ENC_MPG_BUFFERS 4#define IVTV_DEFAULT_ENC_YUV_BUFFERS 2#define IVTV_DEFAULT_ENC_VBI_BUFFERS 1/* Exception: size in kB for this stream (MB is overkill) */#define IVTV_DEFAULT_ENC_PCM_BUFFERS 320#define IVTV_DEFAULT_DEC_MPG_BUFFERS 1#define IVTV_DEFAULT_DEC_YUV_BUFFERS 1/* Exception: size in kB for this stream (MB is way overkill) */#define IVTV_DEFAULT_DEC_VBI_BUFFERS 64static int enc_mpg_buffers = IVTV_DEFAULT_ENC_MPG_BUFFERS;static int enc_yuv_buffers = IVTV_DEFAULT_ENC_YUV_BUFFERS;static int enc_vbi_buffers = IVTV_DEFAULT_ENC_VBI_BUFFERS;static int enc_pcm_buffers = IVTV_DEFAULT_ENC_PCM_BUFFERS;static int dec_mpg_buffers = IVTV_DEFAULT_DEC_MPG_BUFFERS;static int dec_yuv_buffers = IVTV_DEFAULT_DEC_YUV_BUFFERS;static int dec_vbi_buffers = IVTV_DEFAULT_DEC_VBI_BUFFERS;static int ivtv_yuv_mode = 0;static int ivtv_yuv_threshold=-1;static int ivtv_pci_latency = 1;int ivtv_debug = 0;static int newi2c = -1;module_param_array(tuner, int, &tuner_c, 0644);module_param_array(radio, bool, &radio_c, 0644);module_param_array(cardtype, int, &cardtype_c, 0644);module_param_string(pal, pal, sizeof(pal), 0644);module_param_string(secam, secam, sizeof(secam), 0644);module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);module_param_named(debug,ivtv_debug, int, 0644);module_param(ivtv_pci_latency, int, 0644);module_param(ivtv_yuv_mode, int, 0644);module_param(ivtv_yuv_threshold, int, 0644);module_param(ivtv_first_minor, int, 0644);module_param(enc_mpg_buffers, int, 0644);module_param(enc_yuv_buffers, int, 0644);module_param(enc_vbi_buffers, int, 0644);module_param(enc_pcm_buffers, int, 0644);module_param(dec_mpg_buffers, int, 0644);module_param(dec_yuv_buffers, int, 0644);module_param(dec_vbi_buffers, int, 0644);module_param(newi2c, int, 0644);MODULE_PARM_DESC(tuner, "Tuner type selection,\n" "\t\t\tsee tuner.h for values");MODULE_PARM_DESC(radio, "Enable or disable the radio. Use only if autodetection\n" "\t\t\tfails. 0 = disable, 1 = enable");MODULE_PARM_DESC(cardtype, "Only use this option if your card is not detected properly.\n" "\t\tSpecify card type:\n" "\t\t\t 1 = WinTV PVR 250\n" "\t\t\t 2 = WinTV PVR 350\n" "\t\t\t 3 = WinTV PVR-150 or PVR-500\n" "\t\t\t 4 = AVerMedia M179\n" "\t\t\t 5 = YUAN MPG600/Kuroutoshikou iTVC16-STVLP\n" "\t\t\t 6 = YUAN MPG160/Kuroutoshikou iTVC15-STVLP\n" "\t\t\t 7 = YUAN PG600/DIAMONDMM PVR-550 (CX Falcon 2)\n" "\t\t\t 8 = Adaptec AVC-2410\n" "\t\t\t 9 = Adaptec AVC-2010\n" "\t\t\t10 = NAGASE TRANSGEAR 5000TV\n" "\t\t\t11 = AOpen VA2000MAX-STN6\n" "\t\t\t12 = YUAN MPG600GR/Kuroutoshikou CX23416GYC-STVLP\n" "\t\t\t13 = I/O Data GV-MVP/RX\n" "\t\t\t14 = I/O Data GV-MVP/RX2E\n" "\t\t\t15 = GOTVIEW PCI DVD\n" "\t\t\t16 = GOTVIEW PCI DVD2 Deluxe\n" "\t\t\t17 = Yuan MPC622\n" "\t\t\t18 = Digital Cowboy DCT-MTVP1\n" "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite\n" "\t\t\t20 = Club3D ZAP-TV1x01\n" "\t\t\t21 = AverTV MCE 116 Plus\n" "\t\t\t 0 = Autodetect (default)\n" "\t\t\t-1 = Ignore this card\n\t\t");MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC");MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K");MODULE_PARM_DESC(debug, "Debug level (bitmask). Default: 0\n" "\t\t\t 1/0x0001: warning\n" "\t\t\t 2/0x0002: info\n" "\t\t\t 4/0x0004: mailbox\n" "\t\t\t 8/0x0008: ioctl\n" "\t\t\t 16/0x0010: file\n" "\t\t\t 32/0x0020: dma\n" "\t\t\t 64/0x0040: irq\n" "\t\t\t 128/0x0080: decoder\n" "\t\t\t 256/0x0100: yuv\n" "\t\t\t 512/0x0200: i2c\n" "\t\t\t1024/0x0400: high volume\n");MODULE_PARM_DESC(ivtv_pci_latency, "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" "\t\t\tDefault: Yes");MODULE_PARM_DESC(ivtv_yuv_mode, "Specify the yuv playback mode:\n" "\t\t\t0 = interlaced\n\t\t\t1 = progressive\n\t\t\t2 = auto\n" "\t\t\tDefault: 0 (interlaced)");MODULE_PARM_DESC(ivtv_yuv_threshold, "If ivtv_yuv_mode is 2 (auto) then playback content as\n\t\tprogressive if src height <= ivtv_yuvthreshold\n" "\t\t\tDefault: 480");;MODULE_PARM_DESC(enc_mpg_buffers, "Encoder MPG Buffers (in MB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_MPG_BUFFERS));MODULE_PARM_DESC(enc_yuv_buffers, "Encoder YUV Buffers (in MB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_YUV_BUFFERS));MODULE_PARM_DESC(enc_vbi_buffers, "Encoder VBI Buffers (in MB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_VBI_BUFFERS));MODULE_PARM_DESC(enc_pcm_buffers, "Encoder PCM buffers (in kB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_PCM_BUFFERS));MODULE_PARM_DESC(dec_mpg_buffers, "Decoder MPG buffers (in MB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_MPG_BUFFERS));MODULE_PARM_DESC(dec_yuv_buffers, "Decoder YUV buffers (in MB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_YUV_BUFFERS));MODULE_PARM_DESC(dec_vbi_buffers, "Decoder VBI buffers (in kB)\n" "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_VBI_BUFFERS));MODULE_PARM_DESC(newi2c, "Use new I2C implementation\n" "\t\t\t-1 is autodetect, 0 is off, 1 is on\n" "\t\t\tDefault is autodetect");MODULE_PARM_DESC(ivtv_first_minor, "Set minor assigned to first card");MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil");MODULE_DESCRIPTION("CX23415/CX23416 driver");MODULE_SUPPORTED_DEVICE ("CX23415/CX23416 MPEG2 encoder (WinTV PVR-150/250/350/500,\n" "\t\t\tYuan MPG series and similar)");MODULE_LICENSE("GPL");MODULE_VERSION(IVTV_VERSION);void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask){ itv->irqmask &= ~mask; write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);}void ivtv_set_irq_mask(struct ivtv *itv, u32 mask){ itv->irqmask |= mask; write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);}int ivtv_set_output_mode(struct ivtv *itv, int mode){ int old_mode; spin_lock(&itv->lock); old_mode = itv->output_mode; if (old_mode == 0) itv->output_mode = old_mode = mode; spin_unlock(&itv->lock); return old_mode;}struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv){ switch (itv->output_mode) { case OUT_MPG: return &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; case OUT_YUV: return &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; default: return NULL; }}int ivtv_waitq(wait_queue_head_t *waitq){ DEFINE_WAIT(wait); prepare_to_wait(waitq, &wait, TASK_INTERRUPTIBLE); schedule(); finish_wait(waitq, &wait); return signal_pending(current) ? -EINTR : 0;}/* Generic utility functions */int ivtv_msleep_timeout(unsigned int msecs, int intr){ int ret; int timeout = msecs_to_jiffies(msecs); do { set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); timeout = schedule_timeout(timeout); if (intr && (ret = signal_pending(current))) return ret; } while (timeout); return 0;}/* Release ioremapped memory */static void ivtv_iounmap(struct ivtv *itv){ if (itv == NULL) return; /* Release registers memory */ if (itv->reg_mem != NULL) { IVTV_DEBUG_INFO("releasing reg_mem\n"); iounmap(itv->reg_mem); itv->reg_mem = NULL; } /* Release io memory */ if (itv->has_cx23415 && itv->dec_mem != NULL) { IVTV_DEBUG_INFO("releasing dec_mem\n"); iounmap(itv->dec_mem); } itv->dec_mem = NULL; /* Release io memory */ if (itv->enc_mem != NULL) { IVTV_DEBUG_INFO("releasing enc_mem\n"); iounmap(itv->enc_mem); itv->enc_mem = NULL; }}/* Hauppauge card? get values from tveeprom */void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv){ u8 eedata[256]; itv->i2c_client.addr = 0xA0 >> 1; tveeprom_read(&itv->i2c_client, eedata, sizeof(eedata)); tveeprom_hauppauge_analog(&itv->i2c_client, tv, eedata);}static void ivtv_process_eeprom(struct ivtv *itv){ struct tveeprom tv; int pci_slot = PCI_SLOT(itv->dev->devfn); ivtv_read_eeprom(itv, &tv); /* Many thanks to Steven Toth from Hauppauge for providing the model numbers */ switch (tv.model) { /* In a few cases the PCI subsystem IDs do not correctly identify the card. A better method is to check the model number from the eeprom instead. */ case 30012 ... 30039: /* Low profile PVR250 */ case 32000 ... 32999: case 48000 ... 48099: /* 48??? range are PVR250s with a cx23415 */ case 48400 ... 48599: itv->card = ivtv_get_card(IVTV_CARD_PVR_250); break; case 48100 ... 48399: case 48600 ... 48999: itv->card = ivtv_get_card(IVTV_CARD_PVR_350); break; case 23000 ... 23999: /* PVR500 */ case 25000 ... 25999: /* Low profile PVR150 */ case 26000 ... 26999: /* Regular PVR150 */ itv->card = ivtv_get_card(IVTV_CARD_PVR_150); break; case 0: IVTV_ERR("Invalid EEPROM\n"); return; default: IVTV_ERR("Unknown model %d, defaulting to PVR-150\n", tv.model); itv->card = ivtv_get_card(IVTV_CARD_PVR_150); break; } switch (tv.model) { /* Old style PVR350 (with an saa7114) uses this input for the tuner. */ case 48254: itv->card = ivtv_get_card(IVTV_CARD_PVR_350_V1); break; default: break; } itv->v4l2_cap = itv->card->v4l2_capabilities; itv->card_name = itv->card->name; /* If this is a PVR500 then it should be possible to detect whether it is the first or second unit by looking at the subsystem device ID: is bit 4 is set, then it is the second unit (according to info from Hauppauge). However, while this works for most cards, I have seen a few PVR500 cards where both units have the same subsystem ID. So instead I look at the reported 'PCI slot' (which is the slot on the PVR500 PCI bridge) and if it is 8, then it is assumed to be the first unit, otherwise it is the second unit. It is possible that it is a different slot when ivtv is used in Xen, in that case I ignore this card here. The worst that can happen is that the card presents itself with a non-working radio device. This detection is needed since the eeprom reports incorrectly that a radio is present on the second unit. */ if (tv.model / 1000 == 23) { itv->card_name = "WinTV PVR 500"; if (pci_slot == 8 || pci_slot == 9) { int is_first = (pci_slot & 1) == 0; itv->card_name = is_first ? "WinTV PVR 500 (unit #1)" : "WinTV PVR 500 (unit #2)"; if (!is_first) { IVTV_INFO("Correcting tveeprom data: no radio present on second unit\n"); tv.has_radio = 0; } } } IVTV_INFO("Autodetected %s\n", itv->card_name); switch (tv.tuner_hauppauge_model) { case 85: case 99: case 112: itv->pvr150_workaround = 1; break; default: break; } if (tv.tuner_type == TUNER_ABSENT) IVTV_ERR("tveeprom cannot autodetect tuner!"); if (itv->options.tuner == -1) itv->options.tuner = tv.tuner_type; if (itv->options.radio == -1) itv->options.radio = (tv.has_radio != 0); /* only enable newi2c if an IR blaster is present */ /* FIXME: for 2.6.20 the test against 2 should be removed */ if (itv->options.newi2c == -1 && tv.has_ir != -1 && tv.has_ir != 2) { itv->options.newi2c = (tv.has_ir & 2) ? 1 : 0; if (itv->options.newi2c) { IVTV_INFO("Reopen i2c bus for IR-blaster support\n"); exit_ivtv_i2c(itv); init_ivtv_i2c(itv); } } if (itv->std != 0) /* user specified tuner standard */ return; /* autodetect tuner standard */ if (tv.tuner_formats & V4L2_STD_PAL) { IVTV_DEBUG_INFO("PAL tuner detected\n"); itv->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H; } else if (tv.tuner_formats & V4L2_STD_NTSC) { IVTV_DEBUG_INFO("NTSC tuner detected\n"); itv->std |= V4L2_STD_NTSC_M; } else if (tv.tuner_formats & V4L2_STD_SECAM) { IVTV_DEBUG_INFO("SECAM tuner detected\n"); itv->std |= V4L2_STD_SECAM_L; } else { IVTV_INFO("No tuner detected, default to NTSC-M\n"); itv->std |= V4L2_STD_NTSC_M; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -