📄 cx18-driver.c
字号:
/* * cx18 driver initialization and card probing * * Derived from ivtv-driver.c * * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> * Copyright (C) 2008 Andy Walls <awalls@radix.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 */#include "cx18-driver.h"#include "cx18-io.h"#include "cx18-version.h"#include "cx18-cards.h"#include "cx18-i2c.h"#include "cx18-irq.h"#include "cx18-gpio.h"#include "cx18-firmware.h"#include "cx18-streams.h"#include "cx18-av-core.h"#include "cx18-scb.h"#include "cx18-mailbox.h"#include "cx18-ioctl.h"#include "tuner-xc2028.h"#include <media/tveeprom.h>/* var to keep track of the number of array elements in use */int cx18_cards_active;/* 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 Compro H900 with. Normally this would give a video1 device together with a radio0 device for the Compro. By setting this to 1 you ensure that radio0 is now also radio1. */int cx18_first_minor;/* Master variable for all cx18 info */struct cx18 *cx18_cards[CX18_MAX_CARDS];/* Protects cx18_cards_active */DEFINE_SPINLOCK(cx18_cards_lock);/* add your revision and whatnot here */static struct pci_device_id cx18_pci_tbl[] __devinitdata = { {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0,}};MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);/* Parameter declarations */static int cardtype[CX18_MAX_CARDS];static int tuner[CX18_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[CX18_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 mmio_ndelay[CX18_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 cardtype_c = 1;static unsigned tuner_c = 1;static unsigned radio_c = 1;static unsigned mmio_ndelay_c = 1;static char pal[] = "--";static char secam[] = "--";static char ntsc[] = "-";/* Buffers */static int enc_mpg_buffers = CX18_DEFAULT_ENC_MPG_BUFFERS;static int enc_ts_buffers = CX18_DEFAULT_ENC_TS_BUFFERS;static int enc_yuv_buffers = CX18_DEFAULT_ENC_YUV_BUFFERS;static int enc_vbi_buffers = CX18_DEFAULT_ENC_VBI_BUFFERS;static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS;static int cx18_pci_latency = 1;int cx18_retry_mmio = 1;int cx18_debug;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_array(mmio_ndelay, int, &mmio_ndelay_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, cx18_debug, int, 0644);module_param_named(retry_mmio, cx18_retry_mmio, int, 0644);module_param(cx18_pci_latency, int, 0644);module_param(cx18_first_minor, int, 0644);module_param(enc_mpg_buffers, int, 0644);module_param(enc_ts_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_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 = Hauppauge HVR 1600 (ESMT memory)\n" "\t\t\t 2 = Hauppauge HVR 1600 (Samsung memory)\n" "\t\t\t 3 = Compro VideoMate H900\n" "\t\t\t 4 = Yuan MPC718\n" "\t\t\t 5 = Conexant Raptor PAL/SECAM\n" "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n" "\t\t\t 7 = Leadtek WinFast PVR2100\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: dma\n" "\t\t\t 16/0x0010: ioctl\n" "\t\t\t 32/0x0020: file\n" "\t\t\t 64/0x0040: i2c\n" "\t\t\t128/0x0080: irq\n" "\t\t\t256/0x0100: high volume\n");MODULE_PARM_DESC(cx18_pci_latency, "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" "\t\t\tDefault: Yes");MODULE_PARM_DESC(retry_mmio, "Check and retry memory mapped IO accesses\n" "\t\t\tDefault: 1 [Yes]");MODULE_PARM_DESC(mmio_ndelay, "Delay (ns) for each CX23418 memory mapped IO access.\n" "\t\t\tTry larger values that are close to a multiple of the\n" "\t\t\tPCI clock period, 30.3 ns, if your card doesn't work.\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_MMIO_NDELAY));MODULE_PARM_DESC(enc_mpg_buffers, "Encoder MPG Buffers (in MB)\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS));MODULE_PARM_DESC(enc_ts_buffers, "Encoder TS Buffers (in MB)\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFFERS));MODULE_PARM_DESC(enc_yuv_buffers, "Encoder YUV Buffers (in MB)\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS));MODULE_PARM_DESC(enc_vbi_buffers, "Encoder VBI Buffers (in MB)\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_VBI_BUFFERS));MODULE_PARM_DESC(enc_pcm_buffers, "Encoder PCM buffers (in MB)\n" "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS));MODULE_PARM_DESC(cx18_first_minor, "Set kernel number assigned to first card");MODULE_AUTHOR("Hans Verkuil");MODULE_DESCRIPTION("CX23418 driver");MODULE_SUPPORTED_DEVICE("CX23418 MPEG2 encoder");MODULE_LICENSE("GPL");MODULE_VERSION(CX18_VERSION);/* Generic utility functions */int cx18_msleep_timeout(unsigned int msecs, int intr){ int timeout = msecs_to_jiffies(msecs); int sig; do { set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); timeout = schedule_timeout(timeout); sig = intr ? signal_pending(current) : 0; } while (!sig && timeout); return sig;}/* Release ioremapped memory */static void cx18_iounmap(struct cx18 *cx){ if (cx == NULL) return; /* Release io memory */ if (cx->enc_mem != NULL) { CX18_DEBUG_INFO("releasing enc_mem\n"); iounmap(cx->enc_mem); cx->enc_mem = NULL; }}/* Hauppauge card? get values from tveeprom */void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv){ u8 eedata[256]; cx->i2c_client[0].addr = 0xA0 >> 1; tveeprom_read(&cx->i2c_client[0], eedata, sizeof(eedata)); tveeprom_hauppauge_analog(&cx->i2c_client[0], tv, eedata);}static void cx18_process_eeprom(struct cx18 *cx){ struct tveeprom tv; cx18_read_eeprom(cx, &tv); /* Many thanks to Steven Toth from Hauppauge for providing the model numbers */ /* Note: the Samsung memory models cannot be reliably determined from the model number. Use the cardtype module option if you have one of these preproduction models. */ switch (tv.model) { case 74000 ... 74999: cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); break; case 0: CX18_ERR("Invalid EEPROM\n"); return; default: CX18_ERR("Unknown model %d, defaulting to HVR-1600\n", tv.model); cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); break; } cx->v4l2_cap = cx->card->v4l2_capabilities; cx->card_name = cx->card->name; cx->card_i2c = cx->card->i2c; CX18_INFO("Autodetected %s\n", cx->card_name); if (tv.tuner_type == TUNER_ABSENT) CX18_ERR("tveeprom cannot autodetect tuner!"); if (cx->options.tuner == -1) cx->options.tuner = tv.tuner_type; if (cx->options.radio == -1) cx->options.radio = (tv.has_radio != 0); if (cx->std != 0) /* user specified tuner standard */ return; /* autodetect tuner standard */ if (tv.tuner_formats & V4L2_STD_PAL) { CX18_DEBUG_INFO("PAL tuner detected\n"); cx->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H; } else if (tv.tuner_formats & V4L2_STD_NTSC) { CX18_DEBUG_INFO("NTSC tuner detected\n"); cx->std |= V4L2_STD_NTSC_M; } else if (tv.tuner_formats & V4L2_STD_SECAM) { CX18_DEBUG_INFO("SECAM tuner detected\n"); cx->std |= V4L2_STD_SECAM_L; } else { CX18_INFO("No tuner detected, default to NTSC-M\n"); cx->std |= V4L2_STD_NTSC_M; }}static v4l2_std_id cx18_parse_std(struct cx18 *cx){ switch (pal[0]) { case '6': return V4L2_STD_PAL_60; case 'b': case 'B': case 'g': case 'G': return V4L2_STD_PAL_BG; case 'h': case 'H': return V4L2_STD_PAL_H; case 'n': case 'N': if (pal[1] == 'c' || pal[1] == 'C') return V4L2_STD_PAL_Nc; return V4L2_STD_PAL_N; case 'i': case 'I': return V4L2_STD_PAL_I; case 'd': case 'D': case 'k': case 'K': return V4L2_STD_PAL_DK; case 'M': case 'm': return V4L2_STD_PAL_M; case '-': break; default: CX18_WARN("pal= argument not recognised\n"); return 0; } switch (secam[0]) { case 'b': case 'B': case 'g': case 'G': case 'h': case 'H': return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; case 'd': case 'D': case 'k': case 'K': return V4L2_STD_SECAM_DK; case 'l': case 'L': if (secam[1] == 'C' || secam[1] == 'c') return V4L2_STD_SECAM_LC; return V4L2_STD_SECAM_L; case '-': break; default: CX18_WARN("secam= argument not recognised\n"); return 0; } switch (ntsc[0]) { case 'm': case 'M': return V4L2_STD_NTSC_M; case 'j': case 'J': return V4L2_STD_NTSC_M_JP; case 'k': case 'K': return V4L2_STD_NTSC_M_KR; case '-': break; default: CX18_WARN("ntsc= argument not recognised\n"); return 0; } /* no match found */ return 0;}static void cx18_process_options(struct cx18 *cx){ int i, j; cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers; cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers; cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers; cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers; cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers; cx->options.cardtype = cardtype[cx->num]; cx->options.tuner = tuner[cx->num]; cx->options.radio = radio[cx->num]; if (mmio_ndelay[cx->num] < 0) cx->options.mmio_ndelay = CX18_DEFAULT_MMIO_NDELAY; else cx->options.mmio_ndelay = mmio_ndelay[cx->num]; cx->std = cx18_parse_std(cx); if (cx->options.cardtype == -1) { CX18_INFO("Ignore card\n"); return; } cx->card = cx18_get_card(cx->options.cardtype - 1); if (cx->card) CX18_INFO("User specified %s card\n", cx->card->name); else if (cx->options.cardtype != 0) CX18_ERR("Unknown user specified type, trying to autodetect card\n"); if (cx->card == NULL) { if (cx->dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) { cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); CX18_INFO("Autodetected Hauppauge card\n"); } } if (cx->card == NULL) { for (i = 0; (cx->card = cx18_get_card(i)); i++) { if (cx->card->pci_list == NULL) continue; for (j = 0; cx->card->pci_list[j].device; j++) { if (cx->dev->device != cx->card->pci_list[j].device) continue; if (cx->dev->subsystem_vendor != cx->card->pci_list[j].subsystem_vendor) continue; if (cx->dev->subsystem_device != cx->card->pci_list[j].subsystem_device) continue; CX18_INFO("Autodetected %s card\n", cx->card->name); goto done; } } }done: if (cx->card == NULL) { cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n", cx->dev->vendor, cx->dev->device); CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n", cx->dev->subsystem_vendor, cx->dev->subsystem_device); CX18_ERR("Defaulting to %s card\n", cx->card->name); CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); CX18_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n"); CX18_ERR("Prefix your subject line with [UNKNOWN CX18 CARD].\n"); } cx->v4l2_cap = cx->card->v4l2_capabilities; cx->card_name = cx->card->name; cx->card_i2c = cx->card->i2c;}/* Precondition: the cx18 structure has been memset to 0. Only the dev and num fields have been filled in. No assumptions on the card type may be made here (see cx18_init_struct2 for that). */static int __devinit cx18_init_struct1(struct cx18 *cx){ cx->base_addr = pci_resource_start(cx->dev, 0); mutex_init(&cx->serialize_lock); mutex_init(&cx->i2c_bus_lock[0]); mutex_init(&cx->i2c_bus_lock[1]); mutex_init(&cx->gpio_lock); spin_lock_init(&cx->lock); spin_lock_init(&cx->dma_reg_lock); /* start counting open_id at 1 */ cx->open_id = 1; /* Initial settings */ cx2341x_fill_defaults(&cx->params); cx->temporal_strength = cx->params.video_temporal_filter; cx->spatial_strength = cx->params.video_spatial_filter; cx->filter_mode = cx->params.video_spatial_filter_mode | (cx->params.video_temporal_filter_mode << 1) | (cx->params.video_median_filter_type << 2); cx->params.port = CX2341X_PORT_MEMORY; cx->params.capabilities = CX2341X_CAP_HAS_TS; init_waitqueue_head(&cx->cap_w); init_waitqueue_head(&cx->mb_apu_waitq); init_waitqueue_head(&cx->mb_cpu_waitq); init_waitqueue_head(&cx->mb_epu_waitq); init_waitqueue_head(&cx->mb_hpu_waitq); init_waitqueue_head(&cx->dma_waitq); /* VBI */ cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced; cx->vbi.raw_size = 1456; cx->vbi.raw_decoder_line_size = 1456; cx->vbi.raw_decoder_sav_odd_field = 0x20; cx->vbi.raw_decoder_sav_even_field = 0x60; cx->vbi.sliced_decoder_line_size = 272; cx->vbi.sliced_decoder_sav_odd_field = 0xB0; cx->vbi.sliced_decoder_sav_even_field = 0xF0; return 0;}/* Second initialization part. Here the card type has been autodetected. */static void __devinit cx18_init_struct2(struct cx18 *cx){ int i; for (i = 0; i < CX18_CARD_MAX_VIDEO_INPUTS; i++) if (cx->card->video_inputs[i].video_type == 0) break; cx->nof_inputs = i; for (i = 0; i < CX18_CARD_MAX_AUDIO_INPUTS; i++) if (cx->card->audio_inputs[i].audio_type == 0) break; cx->nof_audio_inputs = i; /* Find tuner input */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -