Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 driver internal defines and structures |
| 3 | * |
| 4 | * Derived from ivtv-driver.h |
| 5 | * |
| 6 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 21 | * 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef CX18_DRIVER_H |
| 25 | #define CX18_DRIVER_H |
| 26 | |
| 27 | #include <linux/version.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/moduleparam.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/sched.h> |
| 33 | #include <linux/fs.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/i2c.h> |
| 38 | #include <linux/i2c-algo-bit.h> |
| 39 | #include <linux/list.h> |
| 40 | #include <linux/unistd.h> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 41 | #include <linux/pagemap.h> |
| 42 | #include <linux/workqueue.h> |
| 43 | #include <linux/mutex.h> |
Harvey Harrison | 1a651a0 | 2008-10-18 20:28:37 -0700 | [diff] [blame] | 44 | #include <asm/byteorder.h> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 45 | |
| 46 | #include <linux/dvb/video.h> |
| 47 | #include <linux/dvb/audio.h> |
| 48 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 49 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 50 | #include <media/tuner.h> |
| 51 | #include "cx18-mailbox.h" |
| 52 | #include "cx18-av-core.h" |
| 53 | #include "cx23418.h" |
| 54 | |
| 55 | /* DVB */ |
| 56 | #include "demux.h" |
| 57 | #include "dmxdev.h" |
| 58 | #include "dvb_demux.h" |
| 59 | #include "dvb_frontend.h" |
| 60 | #include "dvb_net.h" |
| 61 | #include "dvbdev.h" |
| 62 | |
| 63 | #ifndef CONFIG_PCI |
| 64 | # error "This driver requires kernel PCI support." |
| 65 | #endif |
| 66 | |
Andy Walls | 446f245 | 2008-09-06 16:43:59 -0300 | [diff] [blame] | 67 | /* Default delay to throttle mmio access to the CX23418 */ |
| 68 | #define CX18_DEFAULT_MMIO_NDELAY 0 /* 0 ns = 0 PCI clock(s) / 33 MHz */ |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame] | 69 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 70 | #define CX18_MEM_OFFSET 0x00000000 |
| 71 | #define CX18_MEM_SIZE 0x04000000 |
| 72 | #define CX18_REG_OFFSET 0x02000000 |
| 73 | |
| 74 | /* Maximum cx18 driver instances. */ |
| 75 | #define CX18_MAX_CARDS 32 |
| 76 | |
| 77 | /* Supported cards */ |
| 78 | #define CX18_CARD_HVR_1600_ESMT 0 /* Hauppauge HVR 1600 (ESMT memory) */ |
| 79 | #define CX18_CARD_HVR_1600_SAMSUNG 1 /* Hauppauge HVR 1600 (Samsung memory) */ |
| 80 | #define CX18_CARD_COMPRO_H900 2 /* Compro VideoMate H900 */ |
| 81 | #define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */ |
Sri Deevi | 03c2808 | 2008-06-21 11:06:44 -0300 | [diff] [blame] | 82 | #define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */ |
Andy Walls | 9eee4fb | 2008-10-04 20:28:40 -0300 | [diff] [blame] | 83 | #define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/ |
| 84 | #define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */ |
| 85 | #define CX18_CARD_LAST 6 |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 86 | |
| 87 | #define CX18_ENC_STREAM_TYPE_MPG 0 |
| 88 | #define CX18_ENC_STREAM_TYPE_TS 1 |
| 89 | #define CX18_ENC_STREAM_TYPE_YUV 2 |
| 90 | #define CX18_ENC_STREAM_TYPE_VBI 3 |
| 91 | #define CX18_ENC_STREAM_TYPE_PCM 4 |
| 92 | #define CX18_ENC_STREAM_TYPE_IDX 5 |
| 93 | #define CX18_ENC_STREAM_TYPE_RAD 6 |
| 94 | #define CX18_MAX_STREAMS 7 |
| 95 | |
| 96 | /* system vendor and device IDs */ |
| 97 | #define PCI_VENDOR_ID_CX 0x14f1 |
| 98 | #define PCI_DEVICE_ID_CX23418 0x5b7a |
| 99 | |
| 100 | /* subsystem vendor ID */ |
| 101 | #define CX18_PCI_ID_HAUPPAUGE 0x0070 |
| 102 | #define CX18_PCI_ID_COMPRO 0x185b |
| 103 | #define CX18_PCI_ID_YUAN 0x12ab |
Sri Deevi | 03c2808 | 2008-06-21 11:06:44 -0300 | [diff] [blame] | 104 | #define CX18_PCI_ID_CONEXANT 0x14f1 |
Andy Walls | 9eee4fb | 2008-10-04 20:28:40 -0300 | [diff] [blame] | 105 | #define CX18_PCI_ID_TOSHIBA 0x1179 |
| 106 | #define CX18_PCI_ID_LEADTEK 0x107D |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 107 | |
| 108 | /* ======================================================================== */ |
| 109 | /* ========================== START USER SETTABLE DMA VARIABLES =========== */ |
| 110 | /* ======================================================================== */ |
| 111 | |
| 112 | /* DMA Buffers, Default size in MB allocated */ |
| 113 | #define CX18_DEFAULT_ENC_TS_BUFFERS 1 |
| 114 | #define CX18_DEFAULT_ENC_MPG_BUFFERS 2 |
| 115 | #define CX18_DEFAULT_ENC_IDX_BUFFERS 1 |
| 116 | #define CX18_DEFAULT_ENC_YUV_BUFFERS 2 |
| 117 | #define CX18_DEFAULT_ENC_VBI_BUFFERS 1 |
| 118 | #define CX18_DEFAULT_ENC_PCM_BUFFERS 1 |
| 119 | |
| 120 | /* i2c stuff */ |
| 121 | #define I2C_CLIENTS_MAX 16 |
| 122 | |
| 123 | /* debugging */ |
| 124 | |
| 125 | /* Flag to turn on high volume debugging */ |
| 126 | #define CX18_DBGFLG_WARN (1 << 0) |
| 127 | #define CX18_DBGFLG_INFO (1 << 1) |
| 128 | #define CX18_DBGFLG_API (1 << 2) |
| 129 | #define CX18_DBGFLG_DMA (1 << 3) |
| 130 | #define CX18_DBGFLG_IOCTL (1 << 4) |
| 131 | #define CX18_DBGFLG_FILE (1 << 5) |
| 132 | #define CX18_DBGFLG_I2C (1 << 6) |
| 133 | #define CX18_DBGFLG_IRQ (1 << 7) |
| 134 | /* Flag to turn on high volume debugging */ |
| 135 | #define CX18_DBGFLG_HIGHVOL (1 << 8) |
| 136 | |
| 137 | /* NOTE: extra space before comma in 'cx->num , ## args' is required for |
| 138 | gcc-2.95, otherwise it won't compile. */ |
| 139 | #define CX18_DEBUG(x, type, fmt, args...) \ |
| 140 | do { \ |
| 141 | if ((x) & cx18_debug) \ |
| 142 | printk(KERN_INFO "cx18-%d " type ": " fmt, cx->num , ## args); \ |
| 143 | } while (0) |
| 144 | #define CX18_DEBUG_WARN(fmt, args...) CX18_DEBUG(CX18_DBGFLG_WARN, "warning", fmt , ## args) |
| 145 | #define CX18_DEBUG_INFO(fmt, args...) CX18_DEBUG(CX18_DBGFLG_INFO, "info", fmt , ## args) |
| 146 | #define CX18_DEBUG_API(fmt, args...) CX18_DEBUG(CX18_DBGFLG_API, "api", fmt , ## args) |
| 147 | #define CX18_DEBUG_DMA(fmt, args...) CX18_DEBUG(CX18_DBGFLG_DMA, "dma", fmt , ## args) |
| 148 | #define CX18_DEBUG_IOCTL(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args) |
| 149 | #define CX18_DEBUG_FILE(fmt, args...) CX18_DEBUG(CX18_DBGFLG_FILE, "file", fmt , ## args) |
| 150 | #define CX18_DEBUG_I2C(fmt, args...) CX18_DEBUG(CX18_DBGFLG_I2C, "i2c", fmt , ## args) |
| 151 | #define CX18_DEBUG_IRQ(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IRQ, "irq", fmt , ## args) |
| 152 | |
| 153 | #define CX18_DEBUG_HIGH_VOL(x, type, fmt, args...) \ |
| 154 | do { \ |
| 155 | if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \ |
| 156 | printk(KERN_INFO "cx18%d " type ": " fmt, cx->num , ## args); \ |
| 157 | } while (0) |
| 158 | #define CX18_DEBUG_HI_WARN(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_WARN, "warning", fmt , ## args) |
| 159 | #define CX18_DEBUG_HI_INFO(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_INFO, "info", fmt , ## args) |
| 160 | #define CX18_DEBUG_HI_API(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_API, "api", fmt , ## args) |
| 161 | #define CX18_DEBUG_HI_DMA(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_DMA, "dma", fmt , ## args) |
| 162 | #define CX18_DEBUG_HI_IOCTL(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args) |
| 163 | #define CX18_DEBUG_HI_FILE(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_FILE, "file", fmt , ## args) |
| 164 | #define CX18_DEBUG_HI_I2C(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_I2C, "i2c", fmt , ## args) |
| 165 | #define CX18_DEBUG_HI_IRQ(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IRQ, "irq", fmt , ## args) |
| 166 | |
| 167 | /* Standard kernel messages */ |
| 168 | #define CX18_ERR(fmt, args...) printk(KERN_ERR "cx18-%d: " fmt, cx->num , ## args) |
| 169 | #define CX18_WARN(fmt, args...) printk(KERN_WARNING "cx18-%d: " fmt, cx->num , ## args) |
| 170 | #define CX18_INFO(fmt, args...) printk(KERN_INFO "cx18-%d: " fmt, cx->num , ## args) |
| 171 | |
| 172 | /* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */ |
| 173 | #define MPEG_FRAME_TYPE_IFRAME 1 |
| 174 | #define MPEG_FRAME_TYPE_IFRAME_PFRAME 3 |
| 175 | #define MPEG_FRAME_TYPE_ALL 7 |
| 176 | |
| 177 | #define CX18_MAX_PGM_INDEX (400) |
| 178 | |
Andy Walls | d267d85 | 2008-09-28 21:46:02 -0300 | [diff] [blame] | 179 | extern int cx18_retry_mmio; /* enable check & retry of mmio accesses */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 180 | extern int cx18_debug; |
| 181 | |
| 182 | |
| 183 | struct cx18_options { |
| 184 | int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */ |
| 185 | int cardtype; /* force card type on load */ |
| 186 | int tuner; /* set tuner on load */ |
| 187 | int radio; /* enable/disable radio */ |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame] | 188 | unsigned long mmio_ndelay; /* delay in ns after every PCI mmio access */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | /* per-buffer bit flags */ |
| 192 | #define CX18_F_B_NEED_BUF_SWAP 0 /* this buffer should be byte swapped */ |
| 193 | |
| 194 | /* per-stream, s_flags */ |
| 195 | #define CX18_F_S_CLAIMED 3 /* this stream is claimed */ |
| 196 | #define CX18_F_S_STREAMING 4 /* the fw is decoding/encoding this stream */ |
| 197 | #define CX18_F_S_INTERNAL_USE 5 /* this stream is used internally (sliced VBI processing) */ |
| 198 | #define CX18_F_S_STREAMOFF 7 /* signal end of stream EOS */ |
| 199 | #define CX18_F_S_APPL_IO 8 /* this stream is used read/written by an application */ |
| 200 | |
| 201 | /* per-cx18, i_flags */ |
Andy Walls | 1d6782b | 2008-11-05 00:49:14 -0300 | [diff] [blame] | 202 | #define CX18_F_I_LOADED_FW 0 /* Loaded firmware 1st time */ |
| 203 | #define CX18_F_I_EOS 4 /* End of encoder stream */ |
| 204 | #define CX18_F_I_RADIO_USER 5 /* radio tuner is selected */ |
| 205 | #define CX18_F_I_ENC_PAUSED 13 /* the encoder is paused */ |
| 206 | #define CX18_F_I_HAVE_WORK 15 /* there is work to be done */ |
| 207 | #define CX18_F_I_WORK_HANDLER_DVB 18 /* work to be done for DVB */ |
| 208 | #define CX18_F_I_INITED 21 /* set after first open */ |
| 209 | #define CX18_F_I_FAILED 22 /* set if first open failed */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 210 | |
| 211 | /* These are the VBI types as they appear in the embedded VBI private packets. */ |
| 212 | #define CX18_SLICED_TYPE_TELETEXT_B (1) |
| 213 | #define CX18_SLICED_TYPE_CAPTION_525 (4) |
| 214 | #define CX18_SLICED_TYPE_WSS_625 (5) |
| 215 | #define CX18_SLICED_TYPE_VPS (7) |
| 216 | |
| 217 | struct cx18_buffer { |
| 218 | struct list_head list; |
| 219 | dma_addr_t dma_handle; |
| 220 | u32 id; |
| 221 | unsigned long b_flags; |
| 222 | char *buf; |
| 223 | |
| 224 | u32 bytesused; |
| 225 | u32 readpos; |
| 226 | }; |
| 227 | |
| 228 | struct cx18_queue { |
| 229 | struct list_head list; |
Andy Walls | b04bce4 | 2008-08-22 21:03:11 -0300 | [diff] [blame] | 230 | atomic_t buffers; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 231 | u32 bytesused; |
| 232 | }; |
| 233 | |
| 234 | struct cx18_dvb { |
| 235 | struct dmx_frontend hw_frontend; |
| 236 | struct dmx_frontend mem_frontend; |
| 237 | struct dmxdev dmxdev; |
| 238 | struct dvb_adapter dvb_adapter; |
| 239 | struct dvb_demux demux; |
| 240 | struct dvb_frontend *fe; |
| 241 | struct dvb_net dvbnet; |
| 242 | int enabled; |
| 243 | int feeding; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 244 | struct mutex feedlock; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | struct cx18; /* forward reference */ |
| 248 | struct cx18_scb; /* forward reference */ |
| 249 | |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 250 | #define CX18_INVALID_TASK_HANDLE 0xffffffff |
| 251 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 252 | struct cx18_stream { |
| 253 | /* These first four fields are always set, even if the stream |
| 254 | is not actually created. */ |
| 255 | struct video_device *v4l2dev; /* NULL when stream not created */ |
| 256 | struct cx18 *cx; /* for ease of use */ |
| 257 | const char *name; /* name of the stream */ |
| 258 | int type; /* stream type */ |
| 259 | u32 handle; /* task handle */ |
| 260 | unsigned mdl_offset; |
| 261 | |
| 262 | u32 id; |
| 263 | spinlock_t qlock; /* locks access to the queues */ |
| 264 | unsigned long s_flags; /* status flags, see above */ |
| 265 | int dma; /* can be PCI_DMA_TODEVICE, |
| 266 | PCI_DMA_FROMDEVICE or |
| 267 | PCI_DMA_NONE */ |
| 268 | u64 dma_pts; |
| 269 | wait_queue_head_t waitq; |
| 270 | |
| 271 | /* Buffer Stats */ |
| 272 | u32 buffers; |
| 273 | u32 buf_size; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 274 | |
| 275 | /* Buffer Queues */ |
| 276 | struct cx18_queue q_free; /* free buffers */ |
| 277 | struct cx18_queue q_full; /* full buffers */ |
| 278 | struct cx18_queue q_io; /* waiting for I/O */ |
| 279 | |
| 280 | /* DVB / Digital Transport */ |
| 281 | struct cx18_dvb dvb; |
| 282 | }; |
| 283 | |
| 284 | struct cx18_open_id { |
| 285 | u32 open_id; |
| 286 | int type; |
| 287 | enum v4l2_priority prio; |
| 288 | struct cx18 *cx; |
| 289 | }; |
| 290 | |
| 291 | /* forward declaration of struct defined in cx18-cards.h */ |
| 292 | struct cx18_card; |
| 293 | |
| 294 | |
| 295 | #define CX18_VBI_FRAMES 32 |
| 296 | |
| 297 | /* VBI data */ |
| 298 | struct vbi_info { |
| 299 | u32 enc_size; |
| 300 | u32 frame; |
| 301 | u8 cc_data_odd[256]; |
| 302 | u8 cc_data_even[256]; |
| 303 | int cc_pos; |
| 304 | u8 cc_no_update; |
| 305 | u8 vps[5]; |
| 306 | u8 vps_found; |
| 307 | int wss; |
| 308 | u8 wss_found; |
| 309 | u8 wss_no_update; |
| 310 | u32 raw_decoder_line_size; |
| 311 | u8 raw_decoder_sav_odd_field; |
| 312 | u8 raw_decoder_sav_even_field; |
| 313 | u32 sliced_decoder_line_size; |
| 314 | u8 sliced_decoder_sav_odd_field; |
| 315 | u8 sliced_decoder_sav_even_field; |
| 316 | struct v4l2_format in; |
| 317 | /* convenience pointer to sliced struct in vbi_in union */ |
| 318 | struct v4l2_sliced_vbi_format *sliced_in; |
| 319 | u32 service_set_in; |
| 320 | int insert_mpeg; |
| 321 | |
| 322 | /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines. |
| 323 | One for /dev/vbi0 and one for /dev/vbi8 */ |
| 324 | struct v4l2_sliced_vbi_data sliced_data[36]; |
| 325 | |
| 326 | /* Buffer for VBI data inserted into MPEG stream. |
| 327 | The first byte is a dummy byte that's never used. |
| 328 | The next 16 bytes contain the MPEG header for the VBI data, |
| 329 | the remainder is the actual VBI data. |
| 330 | The max size accepted by the MPEG VBI reinsertion turns out |
| 331 | to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes, |
| 332 | where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is |
| 333 | a single line header byte and 2 * 18 is the number of VBI lines per frame. |
| 334 | |
| 335 | However, it seems that the data must be 1K aligned, so we have to |
| 336 | pad the data until the 1 or 2 K boundary. |
| 337 | |
| 338 | This pointer array will allocate 2049 bytes to store each VBI frame. */ |
| 339 | u8 *sliced_mpeg_data[CX18_VBI_FRAMES]; |
| 340 | u32 sliced_mpeg_size[CX18_VBI_FRAMES]; |
| 341 | struct cx18_buffer sliced_mpeg_buf; |
| 342 | u32 inserted_frame; |
| 343 | |
| 344 | u32 start[2], count; |
| 345 | u32 raw_size; |
| 346 | u32 sliced_size; |
| 347 | }; |
| 348 | |
| 349 | /* Per cx23418, per I2C bus private algo callback data */ |
| 350 | struct cx18_i2c_algo_callback_data { |
| 351 | struct cx18 *cx; |
| 352 | int bus_index; /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */ |
| 353 | }; |
| 354 | |
Andy Walls | f7823f8 | 2008-11-02 18:15:28 -0300 | [diff] [blame] | 355 | #define CX18_MAX_MMIO_WR_RETRIES 10 |
| 356 | #define CX18_MAX_MMIO_RD_RETRIES 2 |
Andy Walls | d267d85 | 2008-09-28 21:46:02 -0300 | [diff] [blame] | 357 | |
| 358 | struct cx18_mmio_stats { |
Andy Walls | f7823f8 | 2008-11-02 18:15:28 -0300 | [diff] [blame] | 359 | atomic_t retried_write[CX18_MAX_MMIO_WR_RETRIES+1]; |
| 360 | atomic_t retried_read[CX18_MAX_MMIO_RD_RETRIES+1]; |
Andy Walls | d267d85 | 2008-09-28 21:46:02 -0300 | [diff] [blame] | 361 | }; |
| 362 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 363 | /* Struct to hold info about cx18 cards */ |
| 364 | struct cx18 { |
| 365 | int num; /* board number, -1 during init! */ |
| 366 | char name[8]; /* board name for printk and interrupts (e.g. 'cx180') */ |
| 367 | struct pci_dev *dev; /* PCI device */ |
| 368 | const struct cx18_card *card; /* card information */ |
| 369 | const char *card_name; /* full name of the card */ |
| 370 | const struct cx18_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */ |
| 371 | u8 is_50hz; |
| 372 | u8 is_60hz; |
| 373 | u8 is_out_50hz; |
| 374 | u8 is_out_60hz; |
| 375 | u8 nof_inputs; /* number of video inputs */ |
| 376 | u8 nof_audio_inputs; /* number of audio inputs */ |
| 377 | u16 buffer_id; /* buffer ID counter */ |
| 378 | u32 v4l2_cap; /* V4L2 capabilities of card */ |
| 379 | u32 hw_flags; /* Hardware description of the board */ |
| 380 | unsigned mdl_offset; |
Andy Walls | 72c2d6d | 2008-11-06 01:15:41 -0300 | [diff] [blame^] | 381 | struct cx18_scb __iomem *scb; /* pointer to SCB */ |
| 382 | struct mutex epu2apu_mb_lock; /* protect driver to chip mailbox in SCB*/ |
| 383 | struct mutex epu2cpu_mb_lock; /* protect driver to chip mailbox in SCB*/ |
| 384 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 385 | |
| 386 | struct cx18_av_state av_state; |
| 387 | |
| 388 | /* codec settings */ |
| 389 | struct cx2341x_mpeg_params params; |
| 390 | u32 filter_mode; |
| 391 | u32 temporal_strength; |
| 392 | u32 spatial_strength; |
| 393 | |
| 394 | /* dualwatch */ |
| 395 | unsigned long dualwatch_jiffies; |
| 396 | u16 dualwatch_stereo_mode; |
| 397 | |
| 398 | /* Digitizer type */ |
| 399 | int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */ |
| 400 | |
| 401 | struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */ |
| 402 | struct cx18_options options; /* User options */ |
| 403 | int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */ |
| 404 | struct cx18_stream streams[CX18_MAX_STREAMS]; /* Stream data */ |
| 405 | unsigned long i_flags; /* global cx18 flags */ |
Hans Verkuil | 31554ae | 2008-05-25 11:21:27 -0300 | [diff] [blame] | 406 | atomic_t ana_capturing; /* count number of active analog capture streams */ |
| 407 | atomic_t tot_capturing; /* total count number of active capture streams */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 408 | spinlock_t lock; /* lock access to this struct */ |
| 409 | int search_pack_header; |
| 410 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 411 | int open_id; /* incremented each time an open occurs, used as |
| 412 | unique ID. Starts at 1, so 0 can be used as |
| 413 | uninitialized value in the stream->id. */ |
| 414 | |
| 415 | u32 base_addr; |
| 416 | struct v4l2_prio_state prio; |
| 417 | |
| 418 | u8 card_rev; |
| 419 | void __iomem *enc_mem, *reg_mem; |
| 420 | |
| 421 | struct vbi_info vbi; |
| 422 | |
| 423 | u32 pgm_info_offset; |
| 424 | u32 pgm_info_num; |
| 425 | u32 pgm_info_write_idx; |
| 426 | u32 pgm_info_read_idx; |
| 427 | struct v4l2_enc_idx_entry pgm_info[CX18_MAX_PGM_INDEX]; |
| 428 | |
| 429 | u64 mpg_data_received; |
| 430 | u64 vbi_data_inserted; |
| 431 | |
| 432 | wait_queue_head_t mb_apu_waitq; |
| 433 | wait_queue_head_t mb_cpu_waitq; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 434 | wait_queue_head_t cap_w; |
| 435 | /* when the current DMA is finished this queue is woken up */ |
| 436 | wait_queue_head_t dma_waitq; |
| 437 | |
Andy Walls | 1d6782b | 2008-11-05 00:49:14 -0300 | [diff] [blame] | 438 | struct work_struct work; |
| 439 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 440 | /* i2c */ |
| 441 | struct i2c_adapter i2c_adap[2]; |
| 442 | struct i2c_algo_bit_data i2c_algo[2]; |
| 443 | struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2]; |
| 444 | struct i2c_client i2c_client[2]; |
| 445 | struct mutex i2c_bus_lock[2]; |
| 446 | struct i2c_client *i2c_clients[I2C_CLIENTS_MAX]; |
| 447 | |
Hans Verkuil | ba60bc6 | 2008-05-25 14:34:36 -0300 | [diff] [blame] | 448 | /* gpio */ |
| 449 | u32 gpio_dir; |
| 450 | u32 gpio_val; |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 451 | struct mutex gpio_lock; |
Hans Verkuil | ba60bc6 | 2008-05-25 14:34:36 -0300 | [diff] [blame] | 452 | |
Andy Walls | d267d85 | 2008-09-28 21:46:02 -0300 | [diff] [blame] | 453 | /* Statistics */ |
| 454 | struct cx18_mmio_stats mmio_stats; |
| 455 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 456 | /* v4l2 and User settings */ |
| 457 | |
| 458 | /* codec settings */ |
| 459 | u32 audio_input; |
| 460 | u32 active_input; |
| 461 | u32 active_output; |
| 462 | v4l2_std_id std; |
| 463 | v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */ |
| 464 | }; |
| 465 | |
| 466 | /* Globals */ |
| 467 | extern struct cx18 *cx18_cards[]; |
| 468 | extern int cx18_cards_active; |
| 469 | extern int cx18_first_minor; |
| 470 | extern spinlock_t cx18_cards_lock; |
| 471 | |
| 472 | /*==============Prototypes==================*/ |
| 473 | |
| 474 | /* Return non-zero if a signal is pending */ |
| 475 | int cx18_msleep_timeout(unsigned int msecs, int intr); |
| 476 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 477 | /* Read Hauppauge eeprom */ |
| 478 | struct tveeprom; /* forward reference */ |
| 479 | void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv); |
| 480 | |
| 481 | /* First-open initialization: load firmware, etc. */ |
| 482 | int cx18_init_on_first_open(struct cx18 *cx); |
| 483 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 484 | #endif /* CX18_DRIVER_H */ |