blob: 74df9c627a96b29f1f7334b29cf7ab83d63471f0 [file] [log] [blame]
Steven Toth443c12282009-05-09 21:17:28 -03001/*
2 * Driver for the NXP SAA7164 PCIe bridge
3 *
Steven Toth9b8b0192010-07-31 14:39:44 -03004 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
Steven Toth443c12282009-05-09 21:17:28 -03005 *
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 Toth7615e432010-07-31 14:44:53 -030051#include <linux/version.h>
52#include <linux/mutex.h>
Steven Toth12d32032010-07-31 15:13:45 -030053#include <linux/crc32.h>
Steven Toth0b62ceb2010-07-31 16:17:51 -030054#include <linux/kthread.h>
55#include <linux/freezer.h>
Steven Toth443c12282009-05-09 21:17:28 -030056
57#include <media/tuner.h>
58#include <media/tveeprom.h>
59#include <media/videobuf-dma-sg.h>
60#include <media/videobuf-dvb.h>
Steven Toth7615e432010-07-31 14:44:53 -030061#include <dvb_demux.h>
62#include <dvb_frontend.h>
63#include <dvb_net.h>
64#include <dvbdev.h>
65#include <dmxdev.h>
66#include <media/v4l2-common.h>
67#include <media/v4l2-ioctl.h>
68#include <media/v4l2-chip-ident.h>
Steven Toth443c12282009-05-09 21:17:28 -030069
70#include "saa7164-reg.h"
71#include "saa7164-types.h"
72
Steven Toth443c12282009-05-09 21:17:28 -030073#define SAA7164_MAXBOARDS 8
74
75#define UNSET (-1U)
76#define SAA7164_BOARD_NOAUTO UNSET
77#define SAA7164_BOARD_UNKNOWN 0
78#define SAA7164_BOARD_UNKNOWN_REV2 1
79#define SAA7164_BOARD_UNKNOWN_REV3 2
80#define SAA7164_BOARD_HAUPPAUGE_HVR2250 3
81#define SAA7164_BOARD_HAUPPAUGE_HVR2200 4
82#define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5
83#define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6
84#define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7
Steven Tothe3335222009-05-11 22:03:07 -030085#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
Steven Toth443c12282009-05-09 21:17:28 -030086
87#define SAA7164_MAX_UNITS 8
88#define SAA7164_TS_NUMBER_OF_LINES 312
Steven Totha97781a2010-07-31 15:27:01 -030089#define SAA7164_PS_NUMBER_OF_LINES 256
Steven Toth443c12282009-05-09 21:17:28 -030090#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
Steven Toth66e1d372010-07-31 15:09:25 -030091#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
Steven Tothe8ce2f22010-07-31 16:06:06 -030092#define SAA7164_MAX_VBI_BUFFERS 64
Steven Toth7615e432010-07-31 14:44:53 -030093
94/* Port related defines */
95#define SAA7164_PORT_TS1 (0)
96#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
97#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
98#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
Steven Tothe8ce2f22010-07-31 16:06:06 -030099#define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1)
100#define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1)
101#define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1)
Steven Toth443c12282009-05-09 21:17:28 -0300102
103#define DBGLVL_FW 4
104#define DBGLVL_DVB 8
105#define DBGLVL_I2C 16
106#define DBGLVL_API 32
107#define DBGLVL_CMD 64
108#define DBGLVL_BUS 128
109#define DBGLVL_IRQ 256
110#define DBGLVL_BUF 512
Steven Toth9b8b0192010-07-31 14:39:44 -0300111#define DBGLVL_ENC 1024
Steven Tothe8ce2f22010-07-31 16:06:06 -0300112#define DBGLVL_VBI 2048
Steven Toth0b62ceb2010-07-31 16:17:51 -0300113#define DBGLVL_THR 4096
Steven Toth1247ff52010-07-31 16:18:35 -0300114#define DBGLVL_CPU 8192
Steven Toth443c12282009-05-09 21:17:28 -0300115
Mauro Carvalho Chehabc7e242ba2010-10-11 17:39:06 -0300116#define SAA7164_NORMS (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443)
Steven Toth7615e432010-07-31 14:44:53 -0300117
Steven Toth443c12282009-05-09 21:17:28 -0300118enum port_t {
119 SAA7164_MPEG_UNDEFINED = 0,
120 SAA7164_MPEG_DVB,
Steven Tothadd3f582010-07-31 14:43:07 -0300121 SAA7164_MPEG_ENCODER,
Steven Tothe8ce2f22010-07-31 16:06:06 -0300122 SAA7164_MPEG_VBI,
Steven Toth443c12282009-05-09 21:17:28 -0300123};
124
125enum saa7164_i2c_bus_nr {
126 SAA7164_I2C_BUS_0 = 0,
127 SAA7164_I2C_BUS_1,
128 SAA7164_I2C_BUS_2,
129};
130
131enum saa7164_buffer_flags {
132 SAA7164_BUFFER_UNDEFINED = 0,
133 SAA7164_BUFFER_FREE,
134 SAA7164_BUFFER_BUSY,
135 SAA7164_BUFFER_FULL
136};
137
138enum saa7164_unit_type {
139 SAA7164_UNIT_UNDEFINED = 0,
140 SAA7164_UNIT_DIGITAL_DEMODULATOR,
141 SAA7164_UNIT_ANALOG_DEMODULATOR,
142 SAA7164_UNIT_TUNER,
143 SAA7164_UNIT_EEPROM,
144 SAA7164_UNIT_ZILOG_IRBLASTER,
145 SAA7164_UNIT_ENCODER,
146};
147
148/* The PCIe bridge doesn't grant direct access to i2c.
149 * Instead, you address i2c devices using a uniqely
150 * allocated 'unitid' value via a messaging API. This
151 * is a problem. The kernel and existing demod/tuner
152 * drivers expect to talk 'i2c', so we have to maintain
153 * a translation layer, and a series of functions to
154 * convert i2c bus + device address into a unit id.
155 */
156struct saa7164_unit {
157 enum saa7164_unit_type type;
158 u8 id;
159 char *name;
160 enum saa7164_i2c_bus_nr i2c_bus_nr;
161 u8 i2c_bus_addr;
162 u8 i2c_reg_len;
163};
164
165struct saa7164_board {
166 char *name;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300167 enum port_t porta, portb, portc,
168 portd, porte, portf;
Steven Toth443c12282009-05-09 21:17:28 -0300169 enum {
170 SAA7164_CHIP_UNDEFINED = 0,
171 SAA7164_CHIP_REV2,
172 SAA7164_CHIP_REV3,
173 } chiprev;
174 struct saa7164_unit unit[SAA7164_MAX_UNITS];
175};
176
177struct saa7164_subid {
178 u16 subvendor;
179 u16 subdevice;
180 u32 card;
181};
182
Steven Toth96d84202010-07-31 16:04:59 -0300183struct saa7164_encoder_fh {
Steven Toth7615e432010-07-31 14:44:53 -0300184 struct saa7164_port *port;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300185// u32 freq;
186// u32 tuner_type;
187 atomic_t v4l_reading;
188};
189
190struct saa7164_vbi_fh {
191 struct saa7164_port *port;
192// u32 freq;
193// u32 tuner_type;
Steven Toth7615e432010-07-31 14:44:53 -0300194 atomic_t v4l_reading;
195};
196
Steven Toth91d80182010-07-31 14:46:51 -0300197struct saa7164_histogram_bucket {
198 u32 val;
199 u32 count;
200 u64 update_time;
201};
202
203struct saa7164_histogram {
204 char name[32];
205 struct saa7164_histogram_bucket counter1[64];
206};
207
Steven Toth7615e432010-07-31 14:44:53 -0300208struct saa7164_user_buffer {
209 struct list_head list;
210
211 /* Attributes */
212 u8 *data;
213 u32 pos;
214 u32 actual_size;
Steven Toth12d32032010-07-31 15:13:45 -0300215
216 u32 crc;
Steven Toth7615e432010-07-31 14:44:53 -0300217};
218
Steven Toth443c12282009-05-09 21:17:28 -0300219struct saa7164_fw_status {
220
221 /* RISC Core details */
222 u32 status;
223 u32 mode;
224 u32 spec;
225 u32 inst;
226 u32 cpuload;
227 u32 remainheap;
228
229 /* Firmware version */
230 u32 version;
231 u32 major;
232 u32 sub;
233 u32 rel;
234 u32 buildnr;
235};
236
237struct saa7164_dvb {
238 struct mutex lock;
239 struct dvb_adapter adapter;
240 struct dvb_frontend *frontend;
241 struct dvb_demux demux;
242 struct dmxdev dmxdev;
243 struct dmx_frontend fe_hw;
244 struct dmx_frontend fe_mem;
245 struct dvb_net net;
246 int feeding;
247};
248
249struct saa7164_i2c {
250 struct saa7164_dev *dev;
251
252 enum saa7164_i2c_bus_nr nr;
253
254 /* I2C I/O */
255 struct i2c_adapter i2c_adap;
256 struct i2c_algo_bit_data i2c_algo;
257 struct i2c_client i2c_client;
258 u32 i2c_rc;
259};
260
Steven Toth7615e432010-07-31 14:44:53 -0300261struct saa7164_ctrl {
262 struct v4l2_queryctrl v;
263};
264
265struct saa7164_tvnorm {
266 char *name;
267 v4l2_std_id id;
268// u32 cxiformat;
269// u32 cxoformat;
270};
271
272struct saa7164_encoder_params {
273 struct saa7164_tvnorm encodernorm;
274 u32 height;
275 u32 width;
276 u32 is_50hz;
277 u32 bitrate; /* bps */
Steven Toth968b11b2010-07-31 14:59:38 -0300278 u32 bitrate_peak; /* bps */
Steven Toth2600d712010-07-31 14:51:30 -0300279 u32 bitrate_mode;
Steven Toth7615e432010-07-31 14:44:53 -0300280 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
281
282 u32 audio_sampling_freq;
283 u32 ctl_mute;
284 u32 ctl_aspect;
Steven Toth3ed43cf2010-07-31 14:58:35 -0300285 u32 refdist;
Steven Toth5fa56cc2010-07-31 15:05:35 -0300286 u32 gop_size;
Steven Toth7615e432010-07-31 14:44:53 -0300287};
288
Steven Tothe8ce2f22010-07-31 16:06:06 -0300289struct saa7164_vbi_params {
290 struct saa7164_tvnorm encodernorm;
291 u32 height;
292 u32 width;
293 u32 is_50hz;
294 u32 bitrate; /* bps */
295 u32 bitrate_peak; /* bps */
296 u32 bitrate_mode;
297 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
298
299 u32 audio_sampling_freq;
300 u32 ctl_mute;
301 u32 ctl_aspect;
302 u32 refdist;
303 u32 gop_size;
304};
305
Steven Tothadd3f582010-07-31 14:43:07 -0300306struct saa7164_port;
Steven Toth443c12282009-05-09 21:17:28 -0300307
308struct saa7164_buffer {
309 struct list_head list;
310
Steven Tothadd3f582010-07-31 14:43:07 -0300311 /* Note of which h/w buffer list index position we occupy */
312 int idx;
Steven Toth443c12282009-05-09 21:17:28 -0300313
Steven Tothadd3f582010-07-31 14:43:07 -0300314 struct saa7164_port *port;
Steven Toth443c12282009-05-09 21:17:28 -0300315
316 /* Hardware Specific */
317 /* PCI Memory allocations */
318 enum saa7164_buffer_flags flags; /* Free, Busy, Full */
319
320 /* A block of page align PCI memory */
321 u32 pci_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300322 u64 __iomem *cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300323 dma_addr_t dma; /* Physical address */
Steven Toth12d32032010-07-31 15:13:45 -0300324 u32 crc; /* Checksum for the entire buffer data */
Steven Toth443c12282009-05-09 21:17:28 -0300325
326 /* A page table that splits the block into a number of entries */
327 u32 pt_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300328 u64 __iomem *pt_cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300329 dma_addr_t pt_dma; /* Physical address */
Steven Tothadd3f582010-07-31 14:43:07 -0300330
331 /* Encoder fops */
332 u32 pos;
333 u32 actual_size;
Steven Toth443c12282009-05-09 21:17:28 -0300334};
335
Steven Tothadd3f582010-07-31 14:43:07 -0300336struct saa7164_port {
Steven Toth443c12282009-05-09 21:17:28 -0300337
338 struct saa7164_dev *dev;
Steven Toth443c12282009-05-09 21:17:28 -0300339 enum port_t type;
Steven Tothadd3f582010-07-31 14:43:07 -0300340 int nr;
Steven Toth443c12282009-05-09 21:17:28 -0300341
Steven Tothadd3f582010-07-31 14:43:07 -0300342 /* --- Generic port attributes --- */
Steven Toth443c12282009-05-09 21:17:28 -0300343
Steven Tothadd3f582010-07-31 14:43:07 -0300344 /* HW stream parameters */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300345 struct tmHWStreamParameters hw_streamingparams;
Steven Toth443c12282009-05-09 21:17:28 -0300346
347 /* DMA configuration values, is seeded during initialization */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300348 struct tmComResDMATermDescrHeader hwcfg;
Steven Toth443c12282009-05-09 21:17:28 -0300349
350 /* hardware specific registers */
351 u32 bufcounter;
352 u32 pitch;
353 u32 bufsize;
354 u32 bufoffset;
355 u32 bufptr32l;
356 u32 bufptr32h;
357 u64 bufptr64;
358
359 u32 numpte; /* Number of entries in array, only valid in head */
Steven Tothadd3f582010-07-31 14:43:07 -0300360
Steven Toth443c12282009-05-09 21:17:28 -0300361 struct mutex dmaqueue_lock;
Steven Toth443c12282009-05-09 21:17:28 -0300362 struct saa7164_buffer dmaqueue;
Steven Tothadd3f582010-07-31 14:43:07 -0300363
Steven Toth91d80182010-07-31 14:46:51 -0300364 u64 last_irq_msecs, last_svc_msecs;
365 u64 last_irq_msecs_diff, last_svc_msecs_diff;
Steven Tothcfbaf332010-07-31 15:49:28 -0300366 u32 last_svc_wp;
367 u32 last_svc_rp;
Steven Toth91d80182010-07-31 14:46:51 -0300368 u64 last_irq_svc_msecs_diff;
Steven Toth58acca12010-07-31 15:10:52 -0300369 u64 last_read_msecs, last_read_msecs_diff;
370 u64 last_poll_msecs, last_poll_msecs_diff;
Steven Toth91d80182010-07-31 14:46:51 -0300371
372 struct saa7164_histogram irq_interval;
373 struct saa7164_histogram svc_interval;
374 struct saa7164_histogram irq_svc_interval;
Steven Toth58acca12010-07-31 15:10:52 -0300375 struct saa7164_histogram read_interval;
376 struct saa7164_histogram poll_interval;
Steven Toth91d80182010-07-31 14:46:51 -0300377
Steven Tothadd3f582010-07-31 14:43:07 -0300378 /* --- DVB Transport Specific --- */
379 struct saa7164_dvb dvb;
380
381 /* --- Encoder/V4L related attributes --- */
Steven Toth7615e432010-07-31 14:44:53 -0300382 /* Encoder */
383 /* Defaults established in saa7164-encoder.c */
384 struct saa7164_tvnorm encodernorm;
385 u32 height;
386 u32 width;
387 u32 freq;
388 u32 ts_packet_size;
389 u32 ts_packet_count;
390 u8 mux_input;
391 u8 encoder_profile;
392 u8 video_format;
393 u8 audio_format;
394 u8 video_resolution;
395 u16 ctl_brightness;
396 u16 ctl_contrast;
397 u16 ctl_hue;
398 u16 ctl_saturation;
399 u16 ctl_sharpness;
400 s8 ctl_volume;
Steven Toth443c12282009-05-09 21:17:28 -0300401
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300402 struct tmComResAFeatureDescrHeader audfeat;
403 struct tmComResEncoderDescrHeader encunit;
404 struct tmComResProcDescrHeader vidproc;
405 struct tmComResExtDevDescrHeader ifunit;
406 struct tmComResTunerDescrHeader tunerunit;
Steven Toth7615e432010-07-31 14:44:53 -0300407
Steven Toth91d80182010-07-31 14:46:51 -0300408 struct work_struct workenc;
409
Steven Tothe8ce2f22010-07-31 16:06:06 -0300410 /* V4L Encoder Video */
Steven Toth7615e432010-07-31 14:44:53 -0300411 struct saa7164_encoder_params encoder_params;
412 struct video_device *v4l_device;
413 atomic_t v4l_reader_count;
Steven Toth7615e432010-07-31 14:44:53 -0300414
415 struct saa7164_buffer list_buf_used;
416 struct saa7164_buffer list_buf_free;
417 wait_queue_head_t wait_read;
Steven Toth9230aca2010-07-31 15:06:49 -0300418
Steven Tothe8ce2f22010-07-31 16:06:06 -0300419 /* V4L VBI */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300420 struct tmComResVBIFormatDescrHeader vbi_fmt_ntsc;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300421 struct saa7164_vbi_params vbi_params;
422
Steven Toth9230aca2010-07-31 15:06:49 -0300423 /* Debug */
424 u32 sync_errors;
425 u32 v_cc_errors;
426 u32 a_cc_errors;
427 u8 last_v_cc;
428 u8 last_a_cc;
Steven Toth1b0e8e42010-07-31 16:01:00 -0300429 u32 done_first_interrupt;
Steven Toth443c12282009-05-09 21:17:28 -0300430};
431
432struct saa7164_dev {
433 struct list_head devlist;
434 atomic_t refcount;
435
436 /* pci stuff */
437 struct pci_dev *pci;
438 unsigned char pci_rev, pci_lat;
439 int pci_bus, pci_slot;
440 u32 __iomem *lmmio;
441 u8 __iomem *bmmio;
442 u32 __iomem *lmmio2;
443 u8 __iomem *bmmio2;
444 int pci_irqmask;
445
446 /* board details */
447 int nr;
448 int hwrevision;
449 u32 board;
Dan Carpenter0e72cc82010-11-02 00:22:23 -0300450 char name[16];
Steven Toth443c12282009-05-09 21:17:28 -0300451
452 /* firmware status */
453 struct saa7164_fw_status fw_status;
Steven Toth22760ed2010-09-05 11:24:50 -0300454 u32 firmwareloaded;
Steven Toth443c12282009-05-09 21:17:28 -0300455
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300456 struct tmComResHWDescr hwdesc;
457 struct tmComResInterfaceDescr intfdesc;
458 struct tmComResBusDescr busdesc;
Steven Toth443c12282009-05-09 21:17:28 -0300459
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300460 struct tmComResBusInfo bus;
Steven Toth443c12282009-05-09 21:17:28 -0300461
Steven Toth1a6450d2009-05-10 14:08:27 -0300462 /* Interrupt status and ack registers */
463 u32 int_status;
464 u32 int_ack;
Steven Toth443c12282009-05-09 21:17:28 -0300465
466 struct cmd cmds[SAA_CMD_MAX_MSG_UNITS];
467 struct mutex lock;
468
469 /* I2c related */
470 struct saa7164_i2c i2c_bus[3];
471
472 /* Transport related */
Mauro Carvalho Chehabc7e242ba2010-10-11 17:39:06 -0300473 struct saa7164_port ports[SAA7164_MAX_PORTS];
Steven Toth443c12282009-05-09 21:17:28 -0300474
475 /* Deferred command/api interrupts handling */
476 struct work_struct workcmd;
477
Steven Toth0b62ceb2010-07-31 16:17:51 -0300478 /* A kernel thread to monitor the firmware log, used
479 * only in debug mode.
480 */
481 struct task_struct *kthread;
482
Steven Toth443c12282009-05-09 21:17:28 -0300483};
484
485extern struct list_head saa7164_devlist;
Steven Tothdd1ee442009-07-30 09:09:30 -0300486extern unsigned int waitsecs;
Steven Toth66e1d372010-07-31 15:09:25 -0300487extern unsigned int encoder_buffers;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300488extern unsigned int vbi_buffers;
Steven Toth443c12282009-05-09 21:17:28 -0300489
490/* ----------------------------------------------------------- */
491/* saa7164-core.c */
492void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
493void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len);
494void saa7164_getfirmwarestatus(struct saa7164_dev *dev);
495u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev);
Steven Toth58acca12010-07-31 15:10:52 -0300496void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val);
Steven Toth443c12282009-05-09 21:17:28 -0300497
498/* ----------------------------------------------------------- */
499/* saa7164-fw.c */
500int saa7164_downloadfirmware(struct saa7164_dev *dev);
501
502/* ----------------------------------------------------------- */
503/* saa7164-i2c.c */
504extern int saa7164_i2c_register(struct saa7164_i2c *bus);
505extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);
506extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
507 unsigned int cmd, void *arg);
508
509/* ----------------------------------------------------------- */
510/* saa7164-bus.c */
511int saa7164_bus_setup(struct saa7164_dev *dev);
512void saa7164_bus_dump(struct saa7164_dev *dev);
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300513int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf);
514int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
Steven Toth443c12282009-05-09 21:17:28 -0300515 void *buf, int peekonly);
516
517/* ----------------------------------------------------------- */
518/* saa7164-cmd.c */
519int saa7164_cmd_send(struct saa7164_dev *dev,
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300520 u8 id, enum tmComResCmd command, u16 controlselector,
Steven Toth443c12282009-05-09 21:17:28 -0300521 u16 size, void *buf);
522void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
Steven Toth39e469a2009-08-12 12:14:37 -0300523int saa7164_irq_dequeue(struct saa7164_dev *dev);
Steven Toth443c12282009-05-09 21:17:28 -0300524
525/* ----------------------------------------------------------- */
526/* saa7164-api.c */
Steven Toth443c12282009-05-09 21:17:28 -0300527int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version);
528int saa7164_api_enum_subdevs(struct saa7164_dev *dev);
529int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
530 u32 datalen, u8 *data);
531int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr,
532 u32 datalen, u8 *data);
533int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr,
534 u32 datalen, u8 *data);
535int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
536int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
537int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
Steven Tothadd3f582010-07-31 14:43:07 -0300538int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
Steven Toth7615e432010-07-31 14:44:53 -0300539int saa7164_api_initialize_dif(struct saa7164_port *port);
540int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
541int saa7164_api_set_encoder(struct saa7164_port *port);
542int saa7164_api_get_encoder(struct saa7164_port *port);
543int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
544int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
545int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
546int saa7164_api_set_videomux(struct saa7164_port *port);
547int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
548int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
549int saa7164_api_set_audio_std(struct saa7164_port *port);
550int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
551int saa7164_api_get_videomux(struct saa7164_port *port);
Steven Tothe8ce2f22010-07-31 16:06:06 -0300552int saa7164_api_set_vbi_format(struct saa7164_port *port);
Steven Tothe48836b2010-07-31 16:08:52 -0300553int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level);
Steven Toth0b62ceb2010-07-31 16:17:51 -0300554int saa7164_api_collect_debug(struct saa7164_dev *dev);
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300555int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i);
Steven Toth443c12282009-05-09 21:17:28 -0300556
557/* ----------------------------------------------------------- */
558/* saa7164-cards.c */
559extern struct saa7164_board saa7164_boards[];
560extern const unsigned int saa7164_bcount;
561
562extern struct saa7164_subid saa7164_subids[];
563extern const unsigned int saa7164_idcount;
564
565extern void saa7164_card_list(struct saa7164_dev *dev);
566extern void saa7164_gpio_setup(struct saa7164_dev *dev);
567extern void saa7164_card_setup(struct saa7164_dev *dev);
568
569extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
570extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
571extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);
572
573/* ----------------------------------------------------------- */
574/* saa7164-dvb.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300575extern int saa7164_dvb_register(struct saa7164_port *port);
576extern int saa7164_dvb_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300577
578/* ----------------------------------------------------------- */
579/* saa7164-buffer.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300580extern struct saa7164_buffer *saa7164_buffer_alloc(
581 struct saa7164_port *port, u32 len);
582extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
583extern void saa7164_buffer_display(struct saa7164_buffer *buf);
584extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
585extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
Steven Toth7615e432010-07-31 14:44:53 -0300586extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
587 struct saa7164_dev *dev, u32 len);
588extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
Steven Toth9230aca2010-07-31 15:06:49 -0300589extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);
Steven Toth7615e432010-07-31 14:44:53 -0300590
Steven Toth7615e432010-07-31 14:44:53 -0300591/* ----------------------------------------------------------- */
592/* saa7164-encoder.c */
593int saa7164_encoder_register(struct saa7164_port *port);
594void saa7164_encoder_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300595
596/* ----------------------------------------------------------- */
Steven Tothe8ce2f22010-07-31 16:06:06 -0300597/* saa7164-vbi.c */
598int saa7164_vbi_register(struct saa7164_port *port);
599void saa7164_vbi_unregister(struct saa7164_port *port);
600
601/* ----------------------------------------------------------- */
Steven Toth443c12282009-05-09 21:17:28 -0300602
Steven Toth1b0e8e42010-07-31 16:01:00 -0300603extern unsigned int crc_checking;
604
Ingo Molnarb1912a852009-09-21 15:23:45 -0300605extern unsigned int saa_debug;
Steven Toth443c12282009-05-09 21:17:28 -0300606#define dprintk(level, fmt, arg...)\
Ingo Molnarb1912a852009-09-21 15:23:45 -0300607 do { if (saa_debug & level)\
Steven Toth443c12282009-05-09 21:17:28 -0300608 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
609 } while (0)
610
611#define log_warn(fmt, arg...)\
612 do { \
613 printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\
614 } while (0)
615
616#define log_err(fmt, arg...)\
617 do { \
618 printk(KERN_ERROR "%s: " fmt, dev->name, ## arg);\
619 } while (0)
620
621#define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2))
Steven Toth207b42c2009-05-09 21:30:05 -0300622#define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
623
Steven Toth443c12282009-05-09 21:17:28 -0300624#define saa7164_readb(reg) readl(dev->bmmio + (reg))
625#define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg))
626