1443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* 2443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * Driver for the NXP SAA7164 PCIe bridge 3443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * 49b8b0199b86eaa595e3ccacb413e955a193f1962Steven Toth * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 5443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * 6443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * This program is free software; you can redistribute it and/or modify 7443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * it under the terms of the GNU General Public License as published by 8443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * the Free Software Foundation; either version 2 of the License, or 9443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * (at your option) any later version. 10443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * 11443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * This program is distributed in the hope that it will be useful, 12443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * but WITHOUT ANY WARRANTY; without even the implied warranty of 13443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * 15443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * GNU General Public License for more details. 16443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * 17443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * You should have received a copy of the GNU General Public License 18443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * along with this program; if not, write to the Free Software 19443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth */ 21443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 22443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* 23443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth Driver architecture 24443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth ******************* 25443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 26443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth saa7164_core.c/buffer.c/cards.c/i2c.c/dvb.c 27443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : Standard Linux driver framework for creating 28443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : exposing and managing interfaces to the rest 29443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : of the kernel or userland. Also uses _fw.c to load 30443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : firmware direct into the PCIe bus, bypassing layers. 31443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth V 32443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth saa7164_api..() : Translate kernel specific functions/features 33443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : into command buffers. 34443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth V 35443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth saa7164_cmd..() : Manages the flow of command packets on/off, 36443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : the bus. Deal with bus errors, timeouts etc. 37443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth V 38443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth saa7164_bus..() : Manage a read/write memory ring buffer in the 39443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | : PCIe Address space. 40443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | 41443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | saa7164_fw...() : Load any frimware 42443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth | | : direct into the device 43443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth V V 44443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth <- ----------------- PCIe address space -------------------- -> 45443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth*/ 46443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 47443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <linux/pci.h> 48443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <linux/i2c.h> 49443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <linux/kdev_t.h> 507615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <linux/mutex.h> 5112d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth#include <linux/crc32.h> 520b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth#include <linux/kthread.h> 530b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth#include <linux/freezer.h> 54443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 55443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <media/tuner.h> 56443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <media/tveeprom.h> 57443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <media/videobuf-dma-sg.h> 58443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include <media/videobuf-dvb.h> 597615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <dvb_demux.h> 607615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <dvb_frontend.h> 617615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <dvb_net.h> 627615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <dvbdev.h> 637615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <dmxdev.h> 647615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <media/v4l2-common.h> 657615e434aefd95181eae099c4f019e021b024eb6Steven Toth#include <media/v4l2-ioctl.h> 66d66de790c77b98589b93cb327bde2cddd2a4c2ccHans Verkuil#include <media/v4l2-device.h> 67443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 68443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include "saa7164-reg.h" 69443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#include "saa7164-types.h" 70443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 71443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_MAXBOARDS 8 72443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 73443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define UNSET (-1U) 74443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_NOAUTO UNSET 75443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_UNKNOWN 0 76443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_UNKNOWN_REV2 1 77443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_UNKNOWN_REV3 2 78443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2250 3 79443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2200 4 80443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5 81443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6 82443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7 83e333522225ac5c4f37ea49c12724e6c67d896214Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8 8462dd28d0c659db29bdb89cfe9f0aefe42f0adfe9Tony Jago#define SAA7164_BOARD_HAUPPAUGE_HVR2200_4 9 85de2fb698c6fb1e968a5ed9cc449024f119ad3853Steven Toth#define SAA7164_BOARD_HAUPPAUGE_HVR2200_5 10 86443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 87443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_MAX_UNITS 8 88443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_TS_NUMBER_OF_LINES 312 89a97781ac918073117bb8e63619c77e0380bbcc8dSteven Toth#define SAA7164_PS_NUMBER_OF_LINES 256 90443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */ 9166e1d37884eb43214292ed433fcffb72692c4838Steven Toth#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */ 92e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth#define SAA7164_MAX_VBI_BUFFERS 64 937615e434aefd95181eae099c4f019e021b024eb6Steven Toth 947615e434aefd95181eae099c4f019e021b024eb6Steven Toth/* Port related defines */ 957615e434aefd95181eae099c4f019e021b024eb6Steven Toth#define SAA7164_PORT_TS1 (0) 967615e434aefd95181eae099c4f019e021b024eb6Steven Toth#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1) 977615e434aefd95181eae099c4f019e021b024eb6Steven Toth#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1) 987615e434aefd95181eae099c4f019e021b024eb6Steven Toth#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1) 99e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth#define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1) 100e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth#define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1) 101e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth#define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1) 102443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 103443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_FW 4 104443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_DVB 8 105443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_I2C 16 106443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_API 32 107443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_CMD 64 108443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_BUS 128 109443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_IRQ 256 110443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define DBGLVL_BUF 512 1119b8b0199b86eaa595e3ccacb413e955a193f1962Steven Toth#define DBGLVL_ENC 1024 112e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth#define DBGLVL_VBI 2048 1130b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth#define DBGLVL_THR 4096 1141247ff5c0acb0fb50b076e390bb770acc95d1d7eSteven Toth#define DBGLVL_CPU 8192 115443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 116bc25068495b110fcdf35a22f43d32637e99fd018Steven Toth#define SAA7164_NORMS \ 117bc25068495b110fcdf35a22f43d32637e99fd018Steven Toth (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443) 1187615e434aefd95181eae099c4f019e021b024eb6Steven Toth 119443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothenum port_t { 120443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_MPEG_UNDEFINED = 0, 121443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_MPEG_DVB, 122add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth SAA7164_MPEG_ENCODER, 123e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth SAA7164_MPEG_VBI, 124443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 125443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 126443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothenum saa7164_i2c_bus_nr { 127443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_I2C_BUS_0 = 0, 128443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_I2C_BUS_1, 129443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_I2C_BUS_2, 130443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 131443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 132443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothenum saa7164_buffer_flags { 133443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_BUFFER_UNDEFINED = 0, 134443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_BUFFER_FREE, 135443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_BUFFER_BUSY, 136443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_BUFFER_FULL 137443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 138443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 139443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothenum saa7164_unit_type { 140443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_UNDEFINED = 0, 141443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_DIGITAL_DEMODULATOR, 142443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_ANALOG_DEMODULATOR, 143443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_TUNER, 144443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_EEPROM, 145443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_ZILOG_IRBLASTER, 146443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_UNIT_ENCODER, 147443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 148443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 149443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* The PCIe bridge doesn't grant direct access to i2c. 150443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * Instead, you address i2c devices using a uniqely 151443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * allocated 'unitid' value via a messaging API. This 152443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * is a problem. The kernel and existing demod/tuner 153443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * drivers expect to talk 'i2c', so we have to maintain 154443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * a translation layer, and a series of functions to 155443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth * convert i2c bus + device address into a unit id. 156443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth */ 157443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_unit { 158443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum saa7164_unit_type type; 159443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u8 id; 160443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth char *name; 161443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum saa7164_i2c_bus_nr i2c_bus_nr; 162443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u8 i2c_bus_addr; 163443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u8 i2c_reg_len; 164443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 165443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 166443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_board { 167443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth char *name; 168e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth enum port_t porta, portb, portc, 169e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth portd, porte, portf; 170443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum { 171443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_CHIP_UNDEFINED = 0, 172443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_CHIP_REV2, 173443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth SAA7164_CHIP_REV3, 174443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth } chiprev; 175443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_unit unit[SAA7164_MAX_UNITS]; 176443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 177443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 178443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_subid { 179443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u16 subvendor; 180443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u16 subdevice; 181443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 card; 182443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 183443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 18496d8420d17809f0b090da3dddb26a3625b1b6e7aSteven Tothstruct saa7164_encoder_fh { 1857615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_port *port; 186e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth atomic_t v4l_reading; 187e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth}; 188e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth 189e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothstruct saa7164_vbi_fh { 190e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth struct saa7164_port *port; 1917615e434aefd95181eae099c4f019e021b024eb6Steven Toth atomic_t v4l_reading; 1927615e434aefd95181eae099c4f019e021b024eb6Steven Toth}; 1937615e434aefd95181eae099c4f019e021b024eb6Steven Toth 19491d80189fab8c473a392d81b6834b8032191c990Steven Tothstruct saa7164_histogram_bucket { 19591d80189fab8c473a392d81b6834b8032191c990Steven Toth u32 val; 19691d80189fab8c473a392d81b6834b8032191c990Steven Toth u32 count; 19791d80189fab8c473a392d81b6834b8032191c990Steven Toth u64 update_time; 19891d80189fab8c473a392d81b6834b8032191c990Steven Toth}; 19991d80189fab8c473a392d81b6834b8032191c990Steven Toth 20091d80189fab8c473a392d81b6834b8032191c990Steven Tothstruct saa7164_histogram { 20191d80189fab8c473a392d81b6834b8032191c990Steven Toth char name[32]; 20291d80189fab8c473a392d81b6834b8032191c990Steven Toth struct saa7164_histogram_bucket counter1[64]; 20391d80189fab8c473a392d81b6834b8032191c990Steven Toth}; 20491d80189fab8c473a392d81b6834b8032191c990Steven Toth 2057615e434aefd95181eae099c4f019e021b024eb6Steven Tothstruct saa7164_user_buffer { 2067615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct list_head list; 2077615e434aefd95181eae099c4f019e021b024eb6Steven Toth 2087615e434aefd95181eae099c4f019e021b024eb6Steven Toth /* Attributes */ 2097615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 *data; 2107615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 pos; 2117615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 actual_size; 21212d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth 21312d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth u32 crc; 2147615e434aefd95181eae099c4f019e021b024eb6Steven Toth}; 2157615e434aefd95181eae099c4f019e021b024eb6Steven Toth 216443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_fw_status { 217443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 218443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* RISC Core details */ 219443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 status; 220443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 mode; 221443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 spec; 222443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 inst; 223443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 cpuload; 224443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 remainheap; 225443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 226443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* Firmware version */ 227443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 version; 228443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 major; 229443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 sub; 230443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 rel; 231443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 buildnr; 232443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 233443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 234443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_dvb { 235443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct mutex lock; 236443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dvb_adapter adapter; 237443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dvb_frontend *frontend; 238443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dvb_demux demux; 239443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dmxdev dmxdev; 240443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dmx_frontend fe_hw; 241443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dmx_frontend fe_mem; 242443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct dvb_net net; 243443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth int feeding; 244443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 245443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 246443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_i2c { 247443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_dev *dev; 248443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 249443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum saa7164_i2c_bus_nr nr; 250443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 251443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* I2C I/O */ 252443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct i2c_adapter i2c_adap; 253443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct i2c_client i2c_client; 254443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 i2c_rc; 255443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 256443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 2577615e434aefd95181eae099c4f019e021b024eb6Steven Tothstruct saa7164_ctrl { 2587615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct v4l2_queryctrl v; 2597615e434aefd95181eae099c4f019e021b024eb6Steven Toth}; 2607615e434aefd95181eae099c4f019e021b024eb6Steven Toth 2617615e434aefd95181eae099c4f019e021b024eb6Steven Tothstruct saa7164_tvnorm { 2627615e434aefd95181eae099c4f019e021b024eb6Steven Toth char *name; 2637615e434aefd95181eae099c4f019e021b024eb6Steven Toth v4l2_std_id id; 2647615e434aefd95181eae099c4f019e021b024eb6Steven Toth}; 2657615e434aefd95181eae099c4f019e021b024eb6Steven Toth 2667615e434aefd95181eae099c4f019e021b024eb6Steven Tothstruct saa7164_encoder_params { 2677615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_tvnorm encodernorm; 2687615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 height; 2697615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 width; 2707615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 is_50hz; 2717615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 bitrate; /* bps */ 272968b11b20143036098a7013817a15615a54383d3Steven Toth u32 bitrate_peak; /* bps */ 2732600d71cc535907e5d95cd31751c587afc370065Steven Toth u32 bitrate_mode; 2747615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */ 2757615e434aefd95181eae099c4f019e021b024eb6Steven Toth 2767615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 audio_sampling_freq; 2777615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 ctl_mute; 2787615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 ctl_aspect; 2793ed43cf96aa9fc565d74855649d8cee0def67f38Steven Toth u32 refdist; 2805fa56ccdacc54f5f694141c1a74f781cf77874bbSteven Toth u32 gop_size; 2817615e434aefd95181eae099c4f019e021b024eb6Steven Toth}; 2827615e434aefd95181eae099c4f019e021b024eb6Steven Toth 283e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothstruct saa7164_vbi_params { 284e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth struct saa7164_tvnorm encodernorm; 285e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 height; 286e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 width; 287e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 is_50hz; 288e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 bitrate; /* bps */ 289e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 bitrate_peak; /* bps */ 290e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 bitrate_mode; 291e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */ 292e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth 293e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 audio_sampling_freq; 294e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 ctl_mute; 295e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 ctl_aspect; 296e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 refdist; 297e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth u32 gop_size; 298e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth}; 299e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth 300add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothstruct saa7164_port; 301443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 302443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_buffer { 303443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct list_head list; 304443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 305add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* Note of which h/w buffer list index position we occupy */ 306add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth int idx; 307443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 308add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth struct saa7164_port *port; 309443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 310443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* Hardware Specific */ 311443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* PCI Memory allocations */ 312443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum saa7164_buffer_flags flags; /* Free, Busy, Full */ 313443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 314443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* A block of page align PCI memory */ 315443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 pci_size; /* PCI allocation size in bytes */ 31612d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth u64 __iomem *cpu; /* Virtual address */ 317443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth dma_addr_t dma; /* Physical address */ 31812d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth u32 crc; /* Checksum for the entire buffer data */ 319443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 320443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* A page table that splits the block into a number of entries */ 321443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 pt_size; /* PCI allocation size in bytes */ 32212d3203e39db306f56611b3f47ba425ca6a409f9Steven Toth u64 __iomem *pt_cpu; /* Virtual address */ 323443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth dma_addr_t pt_dma; /* Physical address */ 324add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth 325add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* Encoder fops */ 326add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth u32 pos; 327add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth u32 actual_size; 328443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 329443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 330add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothstruct saa7164_port { 331443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 332443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_dev *dev; 333443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth enum port_t type; 334add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth int nr; 335443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 336add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* --- Generic port attributes --- */ 337443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 338add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* HW stream parameters */ 3394d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmHWStreamParameters hw_streamingparams; 340443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 341443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* DMA configuration values, is seeded during initialization */ 3424d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResDMATermDescrHeader hwcfg; 343443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 344443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* hardware specific registers */ 345443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 bufcounter; 346443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 pitch; 347443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 bufsize; 348443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 bufoffset; 349443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 bufptr32l; 350443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 bufptr32h; 351443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u64 bufptr64; 352443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 353443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 numpte; /* Number of entries in array, only valid in head */ 354add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth 355443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct mutex dmaqueue_lock; 356443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_buffer dmaqueue; 357add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth 35891d80189fab8c473a392d81b6834b8032191c990Steven Toth u64 last_irq_msecs, last_svc_msecs; 35991d80189fab8c473a392d81b6834b8032191c990Steven Toth u64 last_irq_msecs_diff, last_svc_msecs_diff; 360cfbaf33733b99d214d5616dcb48a690630c19d65Steven Toth u32 last_svc_wp; 361cfbaf33733b99d214d5616dcb48a690630c19d65Steven Toth u32 last_svc_rp; 36291d80189fab8c473a392d81b6834b8032191c990Steven Toth u64 last_irq_svc_msecs_diff; 36358acca1056434dbbbcb3f1aacd759f1039a3169dSteven Toth u64 last_read_msecs, last_read_msecs_diff; 36458acca1056434dbbbcb3f1aacd759f1039a3169dSteven Toth u64 last_poll_msecs, last_poll_msecs_diff; 36591d80189fab8c473a392d81b6834b8032191c990Steven Toth 36691d80189fab8c473a392d81b6834b8032191c990Steven Toth struct saa7164_histogram irq_interval; 36791d80189fab8c473a392d81b6834b8032191c990Steven Toth struct saa7164_histogram svc_interval; 36891d80189fab8c473a392d81b6834b8032191c990Steven Toth struct saa7164_histogram irq_svc_interval; 36958acca1056434dbbbcb3f1aacd759f1039a3169dSteven Toth struct saa7164_histogram read_interval; 37058acca1056434dbbbcb3f1aacd759f1039a3169dSteven Toth struct saa7164_histogram poll_interval; 37191d80189fab8c473a392d81b6834b8032191c990Steven Toth 372add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* --- DVB Transport Specific --- */ 373add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth struct saa7164_dvb dvb; 374add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth 375add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth /* --- Encoder/V4L related attributes --- */ 3767615e434aefd95181eae099c4f019e021b024eb6Steven Toth /* Encoder */ 3777615e434aefd95181eae099c4f019e021b024eb6Steven Toth /* Defaults established in saa7164-encoder.c */ 3787615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_tvnorm encodernorm; 3798d2d41e92d99e25f7d42fc83fc39096d89caa35eHans Verkuil v4l2_std_id std; 3807615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 height; 3817615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 width; 3827615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 freq; 3837615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 ts_packet_size; 3847615e434aefd95181eae099c4f019e021b024eb6Steven Toth u32 ts_packet_count; 3857615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 mux_input; 3867615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 encoder_profile; 3877615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 video_format; 3887615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 audio_format; 3897615e434aefd95181eae099c4f019e021b024eb6Steven Toth u8 video_resolution; 3907615e434aefd95181eae099c4f019e021b024eb6Steven Toth u16 ctl_brightness; 3917615e434aefd95181eae099c4f019e021b024eb6Steven Toth u16 ctl_contrast; 3927615e434aefd95181eae099c4f019e021b024eb6Steven Toth u16 ctl_hue; 3937615e434aefd95181eae099c4f019e021b024eb6Steven Toth u16 ctl_saturation; 3947615e434aefd95181eae099c4f019e021b024eb6Steven Toth u16 ctl_sharpness; 3957615e434aefd95181eae099c4f019e021b024eb6Steven Toth s8 ctl_volume; 3967615e434aefd95181eae099c4f019e021b024eb6Steven Toth 3974d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResAFeatureDescrHeader audfeat; 3984d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResEncoderDescrHeader encunit; 3994d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResProcDescrHeader vidproc; 4004d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResExtDevDescrHeader ifunit; 4014d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResTunerDescrHeader tunerunit; 4027615e434aefd95181eae099c4f019e021b024eb6Steven Toth 40391d80189fab8c473a392d81b6834b8032191c990Steven Toth struct work_struct workenc; 40491d80189fab8c473a392d81b6834b8032191c990Steven Toth 405e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth /* V4L Encoder Video */ 4067615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_encoder_params encoder_params; 4077615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct video_device *v4l_device; 4087615e434aefd95181eae099c4f019e021b024eb6Steven Toth atomic_t v4l_reader_count; 4097615e434aefd95181eae099c4f019e021b024eb6Steven Toth 4107615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_buffer list_buf_used; 4117615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_buffer list_buf_free; 4127615e434aefd95181eae099c4f019e021b024eb6Steven Toth wait_queue_head_t wait_read; 4139230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth 414e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth /* V4L VBI */ 4154d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResVBIFormatDescrHeader vbi_fmt_ntsc; 416e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth struct saa7164_vbi_params vbi_params; 417e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth 4189230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth /* Debug */ 4199230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth u32 sync_errors; 4209230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth u32 v_cc_errors; 4219230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth u32 a_cc_errors; 4229230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth u8 last_v_cc; 4239230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Toth u8 last_a_cc; 4241b0e8e46297a214336d85c8e278a8a004f97889eSteven Toth u32 done_first_interrupt; 425443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 426443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 427443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothstruct saa7164_dev { 428443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct list_head devlist; 429443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth atomic_t refcount; 430443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 431d66de790c77b98589b93cb327bde2cddd2a4c2ccHans Verkuil struct v4l2_device v4l2_dev; 432d66de790c77b98589b93cb327bde2cddd2a4c2ccHans Verkuil 433443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* pci stuff */ 434443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct pci_dev *pci; 435443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth unsigned char pci_rev, pci_lat; 436443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth int pci_bus, pci_slot; 437443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 __iomem *lmmio; 438443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u8 __iomem *bmmio; 439443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 __iomem *lmmio2; 440443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u8 __iomem *bmmio2; 441443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth int pci_irqmask; 442443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 443443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* board details */ 444443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth int nr; 445443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth int hwrevision; 446443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 board; 4470e72cc8b8d48ba05e705f432fb99aaa0ea6737c6Dan Carpenter char name[16]; 448443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 449443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* firmware status */ 450443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_fw_status fw_status; 45122760ed39c2383e7711753e7582dac5d6d5f647cSteven Toth u32 firmwareloaded; 452443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 4534d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResHWDescr hwdesc; 4544d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResInterfaceDescr intfdesc; 4554d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResBusDescr busdesc; 456443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 4574d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab struct tmComResBusInfo bus; 458443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 4591a6450d4d43a4d4caecaa3ca7796cbe8c7cfbba3Steven Toth /* Interrupt status and ack registers */ 4601a6450d4d43a4d4caecaa3ca7796cbe8c7cfbba3Steven Toth u32 int_status; 4611a6450d4d43a4d4caecaa3ca7796cbe8c7cfbba3Steven Toth u32 int_ack; 462443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 463443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct cmd cmds[SAA_CMD_MAX_MSG_UNITS]; 464443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct mutex lock; 465443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 466443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* I2c related */ 467443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct saa7164_i2c i2c_bus[3]; 468443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 469443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* Transport related */ 470c7e242baf73a284eff92444fb58af11439e3a22cMauro Carvalho Chehab struct saa7164_port ports[SAA7164_MAX_PORTS]; 471443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 472443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth /* Deferred command/api interrupts handling */ 473443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth struct work_struct workcmd; 474443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 4750b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth /* A kernel thread to monitor the firmware log, used 4760b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth * only in debug mode. 4770b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth */ 4780b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth struct task_struct *kthread; 4790b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Toth 480443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth}; 481443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 482443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern struct list_head saa7164_devlist; 483dd1ee4442d14f90d4da6b8a2ee37ab922100f250Steven Tothextern unsigned int waitsecs; 48466e1d37884eb43214292ed433fcffb72692c4838Steven Tothextern unsigned int encoder_buffers; 485e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothextern unsigned int vbi_buffers; 486443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 487443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 488443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-core.c */ 489443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothvoid saa7164_dumpregs(struct saa7164_dev *dev, u32 addr); 490443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothvoid saa7164_getfirmwarestatus(struct saa7164_dev *dev); 491443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothu32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev); 49258acca1056434dbbbcb3f1aacd759f1039a3169dSteven Tothvoid saa7164_histogram_update(struct saa7164_histogram *hg, u32 val); 493443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 494443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 495443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-fw.c */ 496443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_downloadfirmware(struct saa7164_dev *dev); 497443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 498443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 499443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-i2c.c */ 500443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern int saa7164_i2c_register(struct saa7164_i2c *bus); 501443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern int saa7164_i2c_unregister(struct saa7164_i2c *bus); 502443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern void saa7164_call_i2c_clients(struct saa7164_i2c *bus, 503443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth unsigned int cmd, void *arg); 504443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 505443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 506443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-bus.c */ 507443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_bus_setup(struct saa7164_dev *dev); 508443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothvoid saa7164_bus_dump(struct saa7164_dev *dev); 509bc25068495b110fcdf35a22f43d32637e99fd018Steven Tothint saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, 510bc25068495b110fcdf35a22f43d32637e99fd018Steven Toth void *buf); 5114d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehabint saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, 512443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth void *buf, int peekonly); 513443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 514443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 515443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-cmd.c */ 516443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_cmd_send(struct saa7164_dev *dev, 5174d270cfb36683f623f2c23f96b695deb1812476eMauro Carvalho Chehab u8 id, enum tmComResCmd command, u16 controlselector, 518443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u16 size, void *buf); 519443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothvoid saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno); 52039e469ab6dee0977a6fb632c711fba1ec5fca401Steven Tothint saa7164_irq_dequeue(struct saa7164_dev *dev); 521443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 522443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 523443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-api.c */ 524443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version); 525443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_enum_subdevs(struct saa7164_dev *dev); 526443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg, 527443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 datalen, u8 *data); 528443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, 529443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 datalen, u8 *data); 530443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr, 531443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth u32 datalen, u8 *data); 532443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen); 533443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin); 534443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothint saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin); 535add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothint saa7164_api_transition_port(struct saa7164_port *port, u8 mode); 5367615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_initialize_dif(struct saa7164_port *port); 5377615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_configure_dif(struct saa7164_port *port, u32 std); 5387615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_encoder(struct saa7164_port *port); 5397615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_get_encoder(struct saa7164_port *port); 5407615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_aspect_ratio(struct saa7164_port *port); 5417615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl); 5427615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl); 5437615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_videomux(struct saa7164_port *port); 5447615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_audio_mute(struct saa7164_port *port, int mute); 5457615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level); 5467615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_audio_std(struct saa7164_port *port); 5477615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect); 5487615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_api_get_videomux(struct saa7164_port *port); 549e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothint saa7164_api_set_vbi_format(struct saa7164_port *port); 550e48836b8bd7252b3a53eaa355c10322b3f5d236bSteven Tothint saa7164_api_set_debug(struct saa7164_dev *dev, u8 level); 5510b62ceb03545099f0ab43a787cef5307b34b2fe4Steven Tothint saa7164_api_collect_debug(struct saa7164_dev *dev); 552bc25068495b110fcdf35a22f43d32637e99fd018Steven Tothint saa7164_api_get_load_info(struct saa7164_dev *dev, 553bc25068495b110fcdf35a22f43d32637e99fd018Steven Toth struct tmFwInfoStruct *i); 554443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 555443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 556443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-cards.c */ 557443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern struct saa7164_board saa7164_boards[]; 558443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern const unsigned int saa7164_bcount; 559443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 560443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern struct saa7164_subid saa7164_subids[]; 561443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern const unsigned int saa7164_idcount; 562443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 563443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern void saa7164_card_list(struct saa7164_dev *dev); 564443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern void saa7164_gpio_setup(struct saa7164_dev *dev); 565443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern void saa7164_card_setup(struct saa7164_dev *dev); 566443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 567443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr); 568443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr); 569443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Tothextern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid); 570443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 571443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 572443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-dvb.c */ 573add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern int saa7164_dvb_register(struct saa7164_port *port); 574add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern int saa7164_dvb_unregister(struct saa7164_port *port); 575443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 576443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 577443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* saa7164-buffer.c */ 578add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern struct saa7164_buffer *saa7164_buffer_alloc( 579add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Toth struct saa7164_port *port, u32 len); 580add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern int saa7164_buffer_dealloc(struct saa7164_buffer *buf); 581add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern void saa7164_buffer_display(struct saa7164_buffer *buf); 582add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i); 583add3f580a4342b8bca7e0fb4737fe9eeaefa4319Steven Tothextern int saa7164_buffer_cfg_port(struct saa7164_port *port); 5847615e434aefd95181eae099c4f019e021b024eb6Steven Tothextern struct saa7164_user_buffer *saa7164_buffer_alloc_user( 5857615e434aefd95181eae099c4f019e021b024eb6Steven Toth struct saa7164_dev *dev, u32 len); 5867615e434aefd95181eae099c4f019e021b024eb6Steven Tothextern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf); 5879230acaac461c492ff9dea24bbe6a7f568b62cf6Steven Tothextern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i); 5887615e434aefd95181eae099c4f019e021b024eb6Steven Toth 5897615e434aefd95181eae099c4f019e021b024eb6Steven Toth/* ----------------------------------------------------------- */ 5907615e434aefd95181eae099c4f019e021b024eb6Steven Toth/* saa7164-encoder.c */ 5917615e434aefd95181eae099c4f019e021b024eb6Steven Tothint saa7164_encoder_register(struct saa7164_port *port); 5927615e434aefd95181eae099c4f019e021b024eb6Steven Tothvoid saa7164_encoder_unregister(struct saa7164_port *port); 593443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 594443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth/* ----------------------------------------------------------- */ 595e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth/* saa7164-vbi.c */ 596e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothint saa7164_vbi_register(struct saa7164_port *port); 597e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Tothvoid saa7164_vbi_unregister(struct saa7164_port *port); 598e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth 599e8ce2f21665442a29a2b2d1b25197b05405a7216Steven Toth/* ----------------------------------------------------------- */ 600443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 6011b0e8e46297a214336d85c8e278a8a004f97889eSteven Tothextern unsigned int crc_checking; 6021b0e8e46297a214336d85c8e278a8a004f97889eSteven Toth 603b1912a85b54c27738afe1c4fa069df02d3316f0cIngo Molnarextern unsigned int saa_debug; 604443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define dprintk(level, fmt, arg...)\ 605b1912a85b54c27738afe1c4fa069df02d3316f0cIngo Molnar do { if (saa_debug & level)\ 606443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\ 607443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth } while (0) 608443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 609443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define log_warn(fmt, arg...)\ 610443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth do { \ 611443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\ 612443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth } while (0) 613443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 614443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2)) 615207b42c492cc335806957c139381eb260a808837Steven Toth#define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2)) 616207b42c492cc335806957c139381eb260a808837Steven Toth 617443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define saa7164_readb(reg) readl(dev->bmmio + (reg)) 618443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth#define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg)) 619443c1228d50518f3c550e1fef490a2c9d9246ce7Steven Toth 620