Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the NXP SAA7164 PCIe bridge |
| 3 | * |
Steven Toth | 9b8b019 | 2010-07-31 14:39:44 -0300 | [diff] [blame] | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | Driver architecture |
| 24 | ******************* |
| 25 | |
| 26 | saa7164_core.c/buffer.c/cards.c/i2c.c/dvb.c |
| 27 | | : Standard Linux driver framework for creating |
| 28 | | : exposing and managing interfaces to the rest |
| 29 | | : of the kernel or userland. Also uses _fw.c to load |
| 30 | | : firmware direct into the PCIe bus, bypassing layers. |
| 31 | V |
| 32 | saa7164_api..() : Translate kernel specific functions/features |
| 33 | | : into command buffers. |
| 34 | V |
| 35 | saa7164_cmd..() : Manages the flow of command packets on/off, |
| 36 | | : the bus. Deal with bus errors, timeouts etc. |
| 37 | V |
| 38 | saa7164_bus..() : Manage a read/write memory ring buffer in the |
| 39 | | : PCIe Address space. |
| 40 | | |
| 41 | | saa7164_fw...() : Load any frimware |
| 42 | | | : direct into the device |
| 43 | V V |
| 44 | <- ----------------- PCIe address space -------------------- -> |
| 45 | */ |
| 46 | |
| 47 | #include <linux/pci.h> |
| 48 | #include <linux/i2c.h> |
| 49 | #include <linux/i2c-algo-bit.h> |
| 50 | #include <linux/kdev_t.h> |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 51 | #include <linux/version.h> |
| 52 | #include <linux/mutex.h> |
Steven Toth | 12d3203 | 2010-07-31 15:13:45 -0300 | [diff] [blame] | 53 | #include <linux/crc32.h> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 54 | |
| 55 | #include <media/tuner.h> |
| 56 | #include <media/tveeprom.h> |
| 57 | #include <media/videobuf-dma-sg.h> |
| 58 | #include <media/videobuf-dvb.h> |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 59 | #include <linux/smp_lock.h> |
| 60 | #include <dvb_demux.h> |
| 61 | #include <dvb_frontend.h> |
| 62 | #include <dvb_net.h> |
| 63 | #include <dvbdev.h> |
| 64 | #include <dmxdev.h> |
| 65 | #include <media/v4l2-common.h> |
| 66 | #include <media/v4l2-ioctl.h> |
| 67 | #include <media/v4l2-chip-ident.h> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 68 | |
| 69 | #include "saa7164-reg.h" |
| 70 | #include "saa7164-types.h" |
| 71 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 72 | #define SAA7164_MAXBOARDS 8 |
| 73 | |
| 74 | #define UNSET (-1U) |
| 75 | #define SAA7164_BOARD_NOAUTO UNSET |
| 76 | #define SAA7164_BOARD_UNKNOWN 0 |
| 77 | #define SAA7164_BOARD_UNKNOWN_REV2 1 |
| 78 | #define SAA7164_BOARD_UNKNOWN_REV3 2 |
| 79 | #define SAA7164_BOARD_HAUPPAUGE_HVR2250 3 |
| 80 | #define SAA7164_BOARD_HAUPPAUGE_HVR2200 4 |
| 81 | #define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5 |
| 82 | #define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6 |
| 83 | #define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7 |
Steven Toth | e333522 | 2009-05-11 22:03:07 -0300 | [diff] [blame] | 84 | #define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 85 | |
| 86 | #define SAA7164_MAX_UNITS 8 |
| 87 | #define SAA7164_TS_NUMBER_OF_LINES 312 |
Steven Toth | a97781a | 2010-07-31 15:27:01 -0300 | [diff] [blame] | 88 | #define SAA7164_PS_NUMBER_OF_LINES 256 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 89 | #define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */ |
Steven Toth | 66e1d37 | 2010-07-31 15:09:25 -0300 | [diff] [blame] | 90 | #define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */ |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 91 | #define SAA7164_MAX_VBI_BUFFERS 64 |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 92 | |
| 93 | /* Port related defines */ |
| 94 | #define SAA7164_PORT_TS1 (0) |
| 95 | #define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1) |
| 96 | #define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1) |
| 97 | #define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1) |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 98 | #define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1) |
| 99 | #define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1) |
| 100 | #define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 101 | |
| 102 | #define DBGLVL_FW 4 |
| 103 | #define DBGLVL_DVB 8 |
| 104 | #define DBGLVL_I2C 16 |
| 105 | #define DBGLVL_API 32 |
| 106 | #define DBGLVL_CMD 64 |
| 107 | #define DBGLVL_BUS 128 |
| 108 | #define DBGLVL_IRQ 256 |
| 109 | #define DBGLVL_BUF 512 |
Steven Toth | 9b8b019 | 2010-07-31 14:39:44 -0300 | [diff] [blame] | 110 | #define DBGLVL_ENC 1024 |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 111 | #define DBGLVL_VBI 2048 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 112 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 113 | #define SAA7164_NORMS ( V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 ) |
| 114 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 115 | enum port_t { |
| 116 | SAA7164_MPEG_UNDEFINED = 0, |
| 117 | SAA7164_MPEG_DVB, |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 118 | SAA7164_MPEG_ENCODER, |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 119 | SAA7164_MPEG_VBI, |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | enum saa7164_i2c_bus_nr { |
| 123 | SAA7164_I2C_BUS_0 = 0, |
| 124 | SAA7164_I2C_BUS_1, |
| 125 | SAA7164_I2C_BUS_2, |
| 126 | }; |
| 127 | |
| 128 | enum saa7164_buffer_flags { |
| 129 | SAA7164_BUFFER_UNDEFINED = 0, |
| 130 | SAA7164_BUFFER_FREE, |
| 131 | SAA7164_BUFFER_BUSY, |
| 132 | SAA7164_BUFFER_FULL |
| 133 | }; |
| 134 | |
| 135 | enum saa7164_unit_type { |
| 136 | SAA7164_UNIT_UNDEFINED = 0, |
| 137 | SAA7164_UNIT_DIGITAL_DEMODULATOR, |
| 138 | SAA7164_UNIT_ANALOG_DEMODULATOR, |
| 139 | SAA7164_UNIT_TUNER, |
| 140 | SAA7164_UNIT_EEPROM, |
| 141 | SAA7164_UNIT_ZILOG_IRBLASTER, |
| 142 | SAA7164_UNIT_ENCODER, |
| 143 | }; |
| 144 | |
| 145 | /* The PCIe bridge doesn't grant direct access to i2c. |
| 146 | * Instead, you address i2c devices using a uniqely |
| 147 | * allocated 'unitid' value via a messaging API. This |
| 148 | * is a problem. The kernel and existing demod/tuner |
| 149 | * drivers expect to talk 'i2c', so we have to maintain |
| 150 | * a translation layer, and a series of functions to |
| 151 | * convert i2c bus + device address into a unit id. |
| 152 | */ |
| 153 | struct saa7164_unit { |
| 154 | enum saa7164_unit_type type; |
| 155 | u8 id; |
| 156 | char *name; |
| 157 | enum saa7164_i2c_bus_nr i2c_bus_nr; |
| 158 | u8 i2c_bus_addr; |
| 159 | u8 i2c_reg_len; |
| 160 | }; |
| 161 | |
| 162 | struct saa7164_board { |
| 163 | char *name; |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 164 | enum port_t porta, portb, portc, |
| 165 | portd, porte, portf; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 166 | enum { |
| 167 | SAA7164_CHIP_UNDEFINED = 0, |
| 168 | SAA7164_CHIP_REV2, |
| 169 | SAA7164_CHIP_REV3, |
| 170 | } chiprev; |
| 171 | struct saa7164_unit unit[SAA7164_MAX_UNITS]; |
| 172 | }; |
| 173 | |
| 174 | struct saa7164_subid { |
| 175 | u16 subvendor; |
| 176 | u16 subdevice; |
| 177 | u32 card; |
| 178 | }; |
| 179 | |
Steven Toth | 96d8420 | 2010-07-31 16:04:59 -0300 | [diff] [blame] | 180 | struct saa7164_encoder_fh { |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 181 | struct saa7164_port *port; |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 182 | // u32 freq; |
| 183 | // u32 tuner_type; |
| 184 | atomic_t v4l_reading; |
| 185 | }; |
| 186 | |
| 187 | struct saa7164_vbi_fh { |
| 188 | struct saa7164_port *port; |
| 189 | // u32 freq; |
| 190 | // u32 tuner_type; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 191 | atomic_t v4l_reading; |
| 192 | }; |
| 193 | |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 194 | struct saa7164_histogram_bucket { |
| 195 | u32 val; |
| 196 | u32 count; |
| 197 | u64 update_time; |
| 198 | }; |
| 199 | |
| 200 | struct saa7164_histogram { |
| 201 | char name[32]; |
| 202 | struct saa7164_histogram_bucket counter1[64]; |
| 203 | }; |
| 204 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 205 | struct saa7164_user_buffer { |
| 206 | struct list_head list; |
| 207 | |
| 208 | /* Attributes */ |
| 209 | u8 *data; |
| 210 | u32 pos; |
| 211 | u32 actual_size; |
Steven Toth | 12d3203 | 2010-07-31 15:13:45 -0300 | [diff] [blame] | 212 | |
| 213 | u32 crc; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 214 | }; |
| 215 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 216 | struct saa7164_fw_status { |
| 217 | |
| 218 | /* RISC Core details */ |
| 219 | u32 status; |
| 220 | u32 mode; |
| 221 | u32 spec; |
| 222 | u32 inst; |
| 223 | u32 cpuload; |
| 224 | u32 remainheap; |
| 225 | |
| 226 | /* Firmware version */ |
| 227 | u32 version; |
| 228 | u32 major; |
| 229 | u32 sub; |
| 230 | u32 rel; |
| 231 | u32 buildnr; |
| 232 | }; |
| 233 | |
| 234 | struct saa7164_dvb { |
| 235 | struct mutex lock; |
| 236 | struct dvb_adapter adapter; |
| 237 | struct dvb_frontend *frontend; |
| 238 | struct dvb_demux demux; |
| 239 | struct dmxdev dmxdev; |
| 240 | struct dmx_frontend fe_hw; |
| 241 | struct dmx_frontend fe_mem; |
| 242 | struct dvb_net net; |
| 243 | int feeding; |
| 244 | }; |
| 245 | |
| 246 | struct saa7164_i2c { |
| 247 | struct saa7164_dev *dev; |
| 248 | |
| 249 | enum saa7164_i2c_bus_nr nr; |
| 250 | |
| 251 | /* I2C I/O */ |
| 252 | struct i2c_adapter i2c_adap; |
| 253 | struct i2c_algo_bit_data i2c_algo; |
| 254 | struct i2c_client i2c_client; |
| 255 | u32 i2c_rc; |
| 256 | }; |
| 257 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 258 | struct saa7164_ctrl { |
| 259 | struct v4l2_queryctrl v; |
| 260 | }; |
| 261 | |
| 262 | struct saa7164_tvnorm { |
| 263 | char *name; |
| 264 | v4l2_std_id id; |
| 265 | // u32 cxiformat; |
| 266 | // u32 cxoformat; |
| 267 | }; |
| 268 | |
| 269 | struct saa7164_encoder_params { |
| 270 | struct saa7164_tvnorm encodernorm; |
| 271 | u32 height; |
| 272 | u32 width; |
| 273 | u32 is_50hz; |
| 274 | u32 bitrate; /* bps */ |
Steven Toth | 968b11b | 2010-07-31 14:59:38 -0300 | [diff] [blame] | 275 | u32 bitrate_peak; /* bps */ |
Steven Toth | 2600d71 | 2010-07-31 14:51:30 -0300 | [diff] [blame] | 276 | u32 bitrate_mode; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 277 | u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */ |
| 278 | |
| 279 | u32 audio_sampling_freq; |
| 280 | u32 ctl_mute; |
| 281 | u32 ctl_aspect; |
Steven Toth | 3ed43cf | 2010-07-31 14:58:35 -0300 | [diff] [blame] | 282 | u32 refdist; |
Steven Toth | 5fa56cc | 2010-07-31 15:05:35 -0300 | [diff] [blame] | 283 | u32 gop_size; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 284 | }; |
| 285 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 286 | struct saa7164_vbi_params { |
| 287 | struct saa7164_tvnorm encodernorm; |
| 288 | u32 height; |
| 289 | u32 width; |
| 290 | u32 is_50hz; |
| 291 | u32 bitrate; /* bps */ |
| 292 | u32 bitrate_peak; /* bps */ |
| 293 | u32 bitrate_mode; |
| 294 | u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */ |
| 295 | |
| 296 | u32 audio_sampling_freq; |
| 297 | u32 ctl_mute; |
| 298 | u32 ctl_aspect; |
| 299 | u32 refdist; |
| 300 | u32 gop_size; |
| 301 | }; |
| 302 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 303 | struct saa7164_port; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 304 | |
| 305 | struct saa7164_buffer { |
| 306 | struct list_head list; |
| 307 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 308 | /* Note of which h/w buffer list index position we occupy */ |
| 309 | int idx; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 310 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 311 | struct saa7164_port *port; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 312 | |
| 313 | /* Hardware Specific */ |
| 314 | /* PCI Memory allocations */ |
| 315 | enum saa7164_buffer_flags flags; /* Free, Busy, Full */ |
| 316 | |
| 317 | /* A block of page align PCI memory */ |
| 318 | u32 pci_size; /* PCI allocation size in bytes */ |
Steven Toth | 12d3203 | 2010-07-31 15:13:45 -0300 | [diff] [blame] | 319 | u64 __iomem *cpu; /* Virtual address */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 320 | dma_addr_t dma; /* Physical address */ |
Steven Toth | 12d3203 | 2010-07-31 15:13:45 -0300 | [diff] [blame] | 321 | u32 crc; /* Checksum for the entire buffer data */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 322 | |
| 323 | /* A page table that splits the block into a number of entries */ |
| 324 | u32 pt_size; /* PCI allocation size in bytes */ |
Steven Toth | 12d3203 | 2010-07-31 15:13:45 -0300 | [diff] [blame] | 325 | u64 __iomem *pt_cpu; /* Virtual address */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 326 | dma_addr_t pt_dma; /* Physical address */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 327 | |
| 328 | /* Encoder fops */ |
| 329 | u32 pos; |
| 330 | u32 actual_size; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 331 | }; |
| 332 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 333 | struct saa7164_port { |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 334 | |
| 335 | struct saa7164_dev *dev; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 336 | enum port_t type; |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 337 | int nr; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 338 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 339 | /* --- Generic port attributes --- */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 340 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 341 | /* HW stream parameters */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 342 | tmHWStreamParameters_t hw_streamingparams; |
| 343 | |
| 344 | /* DMA configuration values, is seeded during initialization */ |
| 345 | tmComResDMATermDescrHeader_t hwcfg; |
| 346 | |
| 347 | /* hardware specific registers */ |
| 348 | u32 bufcounter; |
| 349 | u32 pitch; |
| 350 | u32 bufsize; |
| 351 | u32 bufoffset; |
| 352 | u32 bufptr32l; |
| 353 | u32 bufptr32h; |
| 354 | u64 bufptr64; |
| 355 | |
| 356 | u32 numpte; /* Number of entries in array, only valid in head */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 357 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 358 | struct mutex dmaqueue_lock; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 359 | struct saa7164_buffer dmaqueue; |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 360 | |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 361 | u64 last_irq_msecs, last_svc_msecs; |
| 362 | u64 last_irq_msecs_diff, last_svc_msecs_diff; |
Steven Toth | cfbaf33 | 2010-07-31 15:49:28 -0300 | [diff] [blame] | 363 | u32 last_svc_wp; |
| 364 | u32 last_svc_rp; |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 365 | u64 last_irq_svc_msecs_diff; |
Steven Toth | 58acca1 | 2010-07-31 15:10:52 -0300 | [diff] [blame] | 366 | u64 last_read_msecs, last_read_msecs_diff; |
| 367 | u64 last_poll_msecs, last_poll_msecs_diff; |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 368 | |
| 369 | struct saa7164_histogram irq_interval; |
| 370 | struct saa7164_histogram svc_interval; |
| 371 | struct saa7164_histogram irq_svc_interval; |
Steven Toth | 58acca1 | 2010-07-31 15:10:52 -0300 | [diff] [blame] | 372 | struct saa7164_histogram read_interval; |
| 373 | struct saa7164_histogram poll_interval; |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 374 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 375 | /* --- DVB Transport Specific --- */ |
| 376 | struct saa7164_dvb dvb; |
| 377 | |
| 378 | /* --- Encoder/V4L related attributes --- */ |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 379 | /* Encoder */ |
| 380 | /* Defaults established in saa7164-encoder.c */ |
| 381 | struct saa7164_tvnorm encodernorm; |
| 382 | u32 height; |
| 383 | u32 width; |
| 384 | u32 freq; |
| 385 | u32 ts_packet_size; |
| 386 | u32 ts_packet_count; |
| 387 | u8 mux_input; |
| 388 | u8 encoder_profile; |
| 389 | u8 video_format; |
| 390 | u8 audio_format; |
| 391 | u8 video_resolution; |
| 392 | u16 ctl_brightness; |
| 393 | u16 ctl_contrast; |
| 394 | u16 ctl_hue; |
| 395 | u16 ctl_saturation; |
| 396 | u16 ctl_sharpness; |
| 397 | s8 ctl_volume; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 398 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 399 | tmComResAFeatureDescrHeader_t audfeat; |
| 400 | tmComResEncoderDescrHeader_t encunit; |
| 401 | tmComResProcDescrHeader_t vidproc; |
| 402 | tmComResExtDevDescrHeader_t ifunit; |
| 403 | tmComResTunerDescrHeader_t tunerunit; |
| 404 | |
Steven Toth | 91d8018 | 2010-07-31 14:46:51 -0300 | [diff] [blame] | 405 | struct work_struct workenc; |
| 406 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 407 | /* V4L Encoder Video */ |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 408 | struct saa7164_encoder_params encoder_params; |
| 409 | struct video_device *v4l_device; |
| 410 | atomic_t v4l_reader_count; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 411 | |
| 412 | struct saa7164_buffer list_buf_used; |
| 413 | struct saa7164_buffer list_buf_free; |
| 414 | wait_queue_head_t wait_read; |
Steven Toth | 9230aca | 2010-07-31 15:06:49 -0300 | [diff] [blame] | 415 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 416 | /* V4L VBI */ |
| 417 | tmComResVBIFormatDescrHeader_t vbi_fmt_ntsc; |
| 418 | struct saa7164_vbi_params vbi_params; |
| 419 | |
Steven Toth | 9230aca | 2010-07-31 15:06:49 -0300 | [diff] [blame] | 420 | /* Debug */ |
| 421 | u32 sync_errors; |
| 422 | u32 v_cc_errors; |
| 423 | u32 a_cc_errors; |
| 424 | u8 last_v_cc; |
| 425 | u8 last_a_cc; |
Steven Toth | 1b0e8e4 | 2010-07-31 16:01:00 -0300 | [diff] [blame] | 426 | u32 done_first_interrupt; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | struct saa7164_dev { |
| 430 | struct list_head devlist; |
| 431 | atomic_t refcount; |
| 432 | |
| 433 | /* pci stuff */ |
| 434 | struct pci_dev *pci; |
| 435 | unsigned char pci_rev, pci_lat; |
| 436 | int pci_bus, pci_slot; |
| 437 | u32 __iomem *lmmio; |
| 438 | u8 __iomem *bmmio; |
| 439 | u32 __iomem *lmmio2; |
| 440 | u8 __iomem *bmmio2; |
| 441 | int pci_irqmask; |
| 442 | |
| 443 | /* board details */ |
| 444 | int nr; |
| 445 | int hwrevision; |
| 446 | u32 board; |
| 447 | char name[32]; |
| 448 | |
| 449 | /* firmware status */ |
| 450 | struct saa7164_fw_status fw_status; |
| 451 | |
| 452 | tmComResHWDescr_t hwdesc; |
| 453 | tmComResInterfaceDescr_t intfdesc; |
| 454 | tmComResBusDescr_t busdesc; |
| 455 | |
| 456 | tmComResBusInfo_t bus; |
| 457 | |
Steven Toth | 1a6450d | 2009-05-10 14:08:27 -0300 | [diff] [blame] | 458 | /* Interrupt status and ack registers */ |
| 459 | u32 int_status; |
| 460 | u32 int_ack; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 461 | |
| 462 | struct cmd cmds[SAA_CMD_MAX_MSG_UNITS]; |
| 463 | struct mutex lock; |
| 464 | |
| 465 | /* I2c related */ |
| 466 | struct saa7164_i2c i2c_bus[3]; |
| 467 | |
| 468 | /* Transport related */ |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 469 | struct saa7164_port ports[ SAA7164_MAX_PORTS ]; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 470 | |
| 471 | /* Deferred command/api interrupts handling */ |
| 472 | struct work_struct workcmd; |
| 473 | |
| 474 | }; |
| 475 | |
| 476 | extern struct list_head saa7164_devlist; |
Steven Toth | dd1ee44 | 2009-07-30 09:09:30 -0300 | [diff] [blame] | 477 | extern unsigned int waitsecs; |
Steven Toth | 66e1d37 | 2010-07-31 15:09:25 -0300 | [diff] [blame] | 478 | extern unsigned int encoder_buffers; |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 479 | extern unsigned int vbi_buffers; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 480 | |
| 481 | /* ----------------------------------------------------------- */ |
| 482 | /* saa7164-core.c */ |
| 483 | void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr); |
| 484 | void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len); |
| 485 | void saa7164_getfirmwarestatus(struct saa7164_dev *dev); |
| 486 | u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev); |
Steven Toth | 58acca1 | 2010-07-31 15:10:52 -0300 | [diff] [blame] | 487 | void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 488 | |
| 489 | /* ----------------------------------------------------------- */ |
| 490 | /* saa7164-fw.c */ |
| 491 | int saa7164_downloadfirmware(struct saa7164_dev *dev); |
| 492 | |
| 493 | /* ----------------------------------------------------------- */ |
| 494 | /* saa7164-i2c.c */ |
| 495 | extern int saa7164_i2c_register(struct saa7164_i2c *bus); |
| 496 | extern int saa7164_i2c_unregister(struct saa7164_i2c *bus); |
| 497 | extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus, |
| 498 | unsigned int cmd, void *arg); |
| 499 | |
| 500 | /* ----------------------------------------------------------- */ |
| 501 | /* saa7164-bus.c */ |
| 502 | int saa7164_bus_setup(struct saa7164_dev *dev); |
| 503 | void saa7164_bus_dump(struct saa7164_dev *dev); |
| 504 | int saa7164_bus_set(struct saa7164_dev *dev, tmComResInfo_t* msg, void *buf); |
| 505 | int saa7164_bus_get(struct saa7164_dev *dev, tmComResInfo_t* msg, |
| 506 | void *buf, int peekonly); |
| 507 | |
| 508 | /* ----------------------------------------------------------- */ |
| 509 | /* saa7164-cmd.c */ |
| 510 | int saa7164_cmd_send(struct saa7164_dev *dev, |
| 511 | u8 id, tmComResCmd_t command, u16 controlselector, |
| 512 | u16 size, void *buf); |
| 513 | void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno); |
Steven Toth | 39e469a | 2009-08-12 12:14:37 -0300 | [diff] [blame] | 514 | int saa7164_irq_dequeue(struct saa7164_dev *dev); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 515 | |
| 516 | /* ----------------------------------------------------------- */ |
| 517 | /* saa7164-api.c */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 518 | int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version); |
| 519 | int saa7164_api_enum_subdevs(struct saa7164_dev *dev); |
| 520 | int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg, |
| 521 | u32 datalen, u8 *data); |
| 522 | int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, |
| 523 | u32 datalen, u8 *data); |
| 524 | int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr, |
| 525 | u32 datalen, u8 *data); |
| 526 | int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen); |
| 527 | int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin); |
| 528 | int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin); |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 529 | int saa7164_api_transition_port(struct saa7164_port *port, u8 mode); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 530 | int saa7164_api_initialize_dif(struct saa7164_port *port); |
| 531 | int saa7164_api_configure_dif(struct saa7164_port *port, u32 std); |
| 532 | int saa7164_api_set_encoder(struct saa7164_port *port); |
| 533 | int saa7164_api_get_encoder(struct saa7164_port *port); |
| 534 | int saa7164_api_set_aspect_ratio(struct saa7164_port *port); |
| 535 | int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl); |
| 536 | int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl); |
| 537 | int saa7164_api_set_videomux(struct saa7164_port *port); |
| 538 | int saa7164_api_audio_mute(struct saa7164_port *port, int mute); |
| 539 | int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level); |
| 540 | int saa7164_api_set_audio_std(struct saa7164_port *port); |
| 541 | int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect); |
| 542 | int saa7164_api_get_videomux(struct saa7164_port *port); |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 543 | int saa7164_api_set_vbi_format(struct saa7164_port *port); |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame^] | 544 | int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level); |
| 545 | int saa7164_api_collect_debug(struct saa7164_dev *dev, struct seq_file *m); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 546 | |
| 547 | /* ----------------------------------------------------------- */ |
| 548 | /* saa7164-cards.c */ |
| 549 | extern struct saa7164_board saa7164_boards[]; |
| 550 | extern const unsigned int saa7164_bcount; |
| 551 | |
| 552 | extern struct saa7164_subid saa7164_subids[]; |
| 553 | extern const unsigned int saa7164_idcount; |
| 554 | |
| 555 | extern void saa7164_card_list(struct saa7164_dev *dev); |
| 556 | extern void saa7164_gpio_setup(struct saa7164_dev *dev); |
| 557 | extern void saa7164_card_setup(struct saa7164_dev *dev); |
| 558 | |
| 559 | extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr); |
| 560 | extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr); |
| 561 | extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid); |
| 562 | |
| 563 | /* ----------------------------------------------------------- */ |
| 564 | /* saa7164-dvb.c */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 565 | extern int saa7164_dvb_register(struct saa7164_port *port); |
| 566 | extern int saa7164_dvb_unregister(struct saa7164_port *port); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 567 | |
| 568 | /* ----------------------------------------------------------- */ |
| 569 | /* saa7164-buffer.c */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 570 | extern struct saa7164_buffer *saa7164_buffer_alloc( |
| 571 | struct saa7164_port *port, u32 len); |
| 572 | extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf); |
| 573 | extern void saa7164_buffer_display(struct saa7164_buffer *buf); |
| 574 | extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i); |
| 575 | extern int saa7164_buffer_cfg_port(struct saa7164_port *port); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 576 | extern struct saa7164_user_buffer *saa7164_buffer_alloc_user( |
| 577 | struct saa7164_dev *dev, u32 len); |
| 578 | extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf); |
Steven Toth | 9230aca | 2010-07-31 15:06:49 -0300 | [diff] [blame] | 579 | extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 580 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 581 | /* ----------------------------------------------------------- */ |
| 582 | /* saa7164-encoder.c */ |
| 583 | int saa7164_encoder_register(struct saa7164_port *port); |
| 584 | void saa7164_encoder_unregister(struct saa7164_port *port); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 585 | |
| 586 | /* ----------------------------------------------------------- */ |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 587 | /* saa7164-vbi.c */ |
| 588 | int saa7164_vbi_register(struct saa7164_port *port); |
| 589 | void saa7164_vbi_unregister(struct saa7164_port *port); |
| 590 | |
| 591 | /* ----------------------------------------------------------- */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 592 | |
Steven Toth | 1b0e8e4 | 2010-07-31 16:01:00 -0300 | [diff] [blame] | 593 | extern unsigned int crc_checking; |
| 594 | |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 595 | extern unsigned int saa_debug; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 596 | #define dprintk(level, fmt, arg...)\ |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 597 | do { if (saa_debug & level)\ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 598 | printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\ |
| 599 | } while (0) |
| 600 | |
| 601 | #define log_warn(fmt, arg...)\ |
| 602 | do { \ |
| 603 | printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\ |
| 604 | } while (0) |
| 605 | |
| 606 | #define log_err(fmt, arg...)\ |
| 607 | do { \ |
| 608 | printk(KERN_ERROR "%s: " fmt, dev->name, ## arg);\ |
| 609 | } while (0) |
| 610 | |
| 611 | #define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2)) |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 612 | #define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2)) |
| 613 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 614 | |
| 615 | #define saa7164_readb(reg) readl(dev->bmmio + (reg)) |
| 616 | #define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg)) |
| 617 | |