blob: 1d9c5cbbbc52cbef4c8f4fe97719967b0f5250b7 [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 <linux/smp_lock.h>
62#include <dvb_demux.h>
63#include <dvb_frontend.h>
64#include <dvb_net.h>
65#include <dvbdev.h>
66#include <dmxdev.h>
67#include <media/v4l2-common.h>
68#include <media/v4l2-ioctl.h>
69#include <media/v4l2-chip-ident.h>
Steven Toth443c12282009-05-09 21:17:28 -030070
71#include "saa7164-reg.h"
72#include "saa7164-types.h"
73
Steven Toth443c12282009-05-09 21:17:28 -030074#define SAA7164_MAXBOARDS 8
75
76#define UNSET (-1U)
77#define SAA7164_BOARD_NOAUTO UNSET
78#define SAA7164_BOARD_UNKNOWN 0
79#define SAA7164_BOARD_UNKNOWN_REV2 1
80#define SAA7164_BOARD_UNKNOWN_REV3 2
81#define SAA7164_BOARD_HAUPPAUGE_HVR2250 3
82#define SAA7164_BOARD_HAUPPAUGE_HVR2200 4
83#define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5
84#define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6
85#define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7
Steven Tothe3335222009-05-11 22:03:07 -030086#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
Steven Toth443c12282009-05-09 21:17:28 -030087
88#define SAA7164_MAX_UNITS 8
89#define SAA7164_TS_NUMBER_OF_LINES 312
Steven Totha97781a2010-07-31 15:27:01 -030090#define SAA7164_PS_NUMBER_OF_LINES 256
Steven Toth443c12282009-05-09 21:17:28 -030091#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
Steven Toth66e1d372010-07-31 15:09:25 -030092#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
Steven Tothe8ce2f22010-07-31 16:06:06 -030093#define SAA7164_MAX_VBI_BUFFERS 64
Steven Toth7615e432010-07-31 14:44:53 -030094
95/* Port related defines */
96#define SAA7164_PORT_TS1 (0)
97#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
98#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
99#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
Steven Tothe8ce2f22010-07-31 16:06:06 -0300100#define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1)
101#define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1)
102#define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1)
Steven Toth443c12282009-05-09 21:17:28 -0300103
104#define DBGLVL_FW 4
105#define DBGLVL_DVB 8
106#define DBGLVL_I2C 16
107#define DBGLVL_API 32
108#define DBGLVL_CMD 64
109#define DBGLVL_BUS 128
110#define DBGLVL_IRQ 256
111#define DBGLVL_BUF 512
Steven Toth9b8b0192010-07-31 14:39:44 -0300112#define DBGLVL_ENC 1024
Steven Tothe8ce2f22010-07-31 16:06:06 -0300113#define DBGLVL_VBI 2048
Steven Toth0b62ceb2010-07-31 16:17:51 -0300114#define DBGLVL_THR 4096
Steven Toth1247ff52010-07-31 16:18:35 -0300115#define DBGLVL_CPU 8192
Steven Toth443c12282009-05-09 21:17:28 -0300116
Mauro Carvalho Chehabc7e242ba2010-10-11 17:39:06 -0300117#define SAA7164_NORMS (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443)
Steven Toth7615e432010-07-31 14:44:53 -0300118
Steven Toth443c12282009-05-09 21:17:28 -0300119enum port_t {
120 SAA7164_MPEG_UNDEFINED = 0,
121 SAA7164_MPEG_DVB,
Steven Tothadd3f582010-07-31 14:43:07 -0300122 SAA7164_MPEG_ENCODER,
Steven Tothe8ce2f22010-07-31 16:06:06 -0300123 SAA7164_MPEG_VBI,
Steven Toth443c12282009-05-09 21:17:28 -0300124};
125
126enum saa7164_i2c_bus_nr {
127 SAA7164_I2C_BUS_0 = 0,
128 SAA7164_I2C_BUS_1,
129 SAA7164_I2C_BUS_2,
130};
131
132enum saa7164_buffer_flags {
133 SAA7164_BUFFER_UNDEFINED = 0,
134 SAA7164_BUFFER_FREE,
135 SAA7164_BUFFER_BUSY,
136 SAA7164_BUFFER_FULL
137};
138
139enum saa7164_unit_type {
140 SAA7164_UNIT_UNDEFINED = 0,
141 SAA7164_UNIT_DIGITAL_DEMODULATOR,
142 SAA7164_UNIT_ANALOG_DEMODULATOR,
143 SAA7164_UNIT_TUNER,
144 SAA7164_UNIT_EEPROM,
145 SAA7164_UNIT_ZILOG_IRBLASTER,
146 SAA7164_UNIT_ENCODER,
147};
148
149/* The PCIe bridge doesn't grant direct access to i2c.
150 * Instead, you address i2c devices using a uniqely
151 * allocated 'unitid' value via a messaging API. This
152 * is a problem. The kernel and existing demod/tuner
153 * drivers expect to talk 'i2c', so we have to maintain
154 * a translation layer, and a series of functions to
155 * convert i2c bus + device address into a unit id.
156 */
157struct saa7164_unit {
158 enum saa7164_unit_type type;
159 u8 id;
160 char *name;
161 enum saa7164_i2c_bus_nr i2c_bus_nr;
162 u8 i2c_bus_addr;
163 u8 i2c_reg_len;
164};
165
166struct saa7164_board {
167 char *name;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300168 enum port_t porta, portb, portc,
169 portd, porte, portf;
Steven Toth443c12282009-05-09 21:17:28 -0300170 enum {
171 SAA7164_CHIP_UNDEFINED = 0,
172 SAA7164_CHIP_REV2,
173 SAA7164_CHIP_REV3,
174 } chiprev;
175 struct saa7164_unit unit[SAA7164_MAX_UNITS];
176};
177
178struct saa7164_subid {
179 u16 subvendor;
180 u16 subdevice;
181 u32 card;
182};
183
Steven Toth96d84202010-07-31 16:04:59 -0300184struct saa7164_encoder_fh {
Steven Toth7615e432010-07-31 14:44:53 -0300185 struct saa7164_port *port;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300186// u32 freq;
187// u32 tuner_type;
188 atomic_t v4l_reading;
189};
190
191struct saa7164_vbi_fh {
192 struct saa7164_port *port;
193// u32 freq;
194// u32 tuner_type;
Steven Toth7615e432010-07-31 14:44:53 -0300195 atomic_t v4l_reading;
196};
197
Steven Toth91d80182010-07-31 14:46:51 -0300198struct saa7164_histogram_bucket {
199 u32 val;
200 u32 count;
201 u64 update_time;
202};
203
204struct saa7164_histogram {
205 char name[32];
206 struct saa7164_histogram_bucket counter1[64];
207};
208
Steven Toth7615e432010-07-31 14:44:53 -0300209struct saa7164_user_buffer {
210 struct list_head list;
211
212 /* Attributes */
213 u8 *data;
214 u32 pos;
215 u32 actual_size;
Steven Toth12d32032010-07-31 15:13:45 -0300216
217 u32 crc;
Steven Toth7615e432010-07-31 14:44:53 -0300218};
219
Steven Toth443c12282009-05-09 21:17:28 -0300220struct saa7164_fw_status {
221
222 /* RISC Core details */
223 u32 status;
224 u32 mode;
225 u32 spec;
226 u32 inst;
227 u32 cpuload;
228 u32 remainheap;
229
230 /* Firmware version */
231 u32 version;
232 u32 major;
233 u32 sub;
234 u32 rel;
235 u32 buildnr;
236};
237
238struct saa7164_dvb {
239 struct mutex lock;
240 struct dvb_adapter adapter;
241 struct dvb_frontend *frontend;
242 struct dvb_demux demux;
243 struct dmxdev dmxdev;
244 struct dmx_frontend fe_hw;
245 struct dmx_frontend fe_mem;
246 struct dvb_net net;
247 int feeding;
248};
249
250struct saa7164_i2c {
251 struct saa7164_dev *dev;
252
253 enum saa7164_i2c_bus_nr nr;
254
255 /* I2C I/O */
256 struct i2c_adapter i2c_adap;
257 struct i2c_algo_bit_data i2c_algo;
258 struct i2c_client i2c_client;
259 u32 i2c_rc;
260};
261
Steven Toth7615e432010-07-31 14:44:53 -0300262struct saa7164_ctrl {
263 struct v4l2_queryctrl v;
264};
265
266struct saa7164_tvnorm {
267 char *name;
268 v4l2_std_id id;
269// u32 cxiformat;
270// u32 cxoformat;
271};
272
273struct saa7164_encoder_params {
274 struct saa7164_tvnorm encodernorm;
275 u32 height;
276 u32 width;
277 u32 is_50hz;
278 u32 bitrate; /* bps */
Steven Toth968b11b2010-07-31 14:59:38 -0300279 u32 bitrate_peak; /* bps */
Steven Toth2600d712010-07-31 14:51:30 -0300280 u32 bitrate_mode;
Steven Toth7615e432010-07-31 14:44:53 -0300281 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
282
283 u32 audio_sampling_freq;
284 u32 ctl_mute;
285 u32 ctl_aspect;
Steven Toth3ed43cf2010-07-31 14:58:35 -0300286 u32 refdist;
Steven Toth5fa56cc2010-07-31 15:05:35 -0300287 u32 gop_size;
Steven Toth7615e432010-07-31 14:44:53 -0300288};
289
Steven Tothe8ce2f22010-07-31 16:06:06 -0300290struct saa7164_vbi_params {
291 struct saa7164_tvnorm encodernorm;
292 u32 height;
293 u32 width;
294 u32 is_50hz;
295 u32 bitrate; /* bps */
296 u32 bitrate_peak; /* bps */
297 u32 bitrate_mode;
298 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
299
300 u32 audio_sampling_freq;
301 u32 ctl_mute;
302 u32 ctl_aspect;
303 u32 refdist;
304 u32 gop_size;
305};
306
Steven Tothadd3f582010-07-31 14:43:07 -0300307struct saa7164_port;
Steven Toth443c12282009-05-09 21:17:28 -0300308
309struct saa7164_buffer {
310 struct list_head list;
311
Steven Tothadd3f582010-07-31 14:43:07 -0300312 /* Note of which h/w buffer list index position we occupy */
313 int idx;
Steven Toth443c12282009-05-09 21:17:28 -0300314
Steven Tothadd3f582010-07-31 14:43:07 -0300315 struct saa7164_port *port;
Steven Toth443c12282009-05-09 21:17:28 -0300316
317 /* Hardware Specific */
318 /* PCI Memory allocations */
319 enum saa7164_buffer_flags flags; /* Free, Busy, Full */
320
321 /* A block of page align PCI memory */
322 u32 pci_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300323 u64 __iomem *cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300324 dma_addr_t dma; /* Physical address */
Steven Toth12d32032010-07-31 15:13:45 -0300325 u32 crc; /* Checksum for the entire buffer data */
Steven Toth443c12282009-05-09 21:17:28 -0300326
327 /* A page table that splits the block into a number of entries */
328 u32 pt_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300329 u64 __iomem *pt_cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300330 dma_addr_t pt_dma; /* Physical address */
Steven Tothadd3f582010-07-31 14:43:07 -0300331
332 /* Encoder fops */
333 u32 pos;
334 u32 actual_size;
Steven Toth443c12282009-05-09 21:17:28 -0300335};
336
Steven Tothadd3f582010-07-31 14:43:07 -0300337struct saa7164_port {
Steven Toth443c12282009-05-09 21:17:28 -0300338
339 struct saa7164_dev *dev;
Steven Toth443c12282009-05-09 21:17:28 -0300340 enum port_t type;
Steven Tothadd3f582010-07-31 14:43:07 -0300341 int nr;
Steven Toth443c12282009-05-09 21:17:28 -0300342
Steven Tothadd3f582010-07-31 14:43:07 -0300343 /* --- Generic port attributes --- */
Steven Toth443c12282009-05-09 21:17:28 -0300344
Steven Tothadd3f582010-07-31 14:43:07 -0300345 /* HW stream parameters */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300346 struct tmHWStreamParameters hw_streamingparams;
Steven Toth443c12282009-05-09 21:17:28 -0300347
348 /* DMA configuration values, is seeded during initialization */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300349 struct tmComResDMATermDescrHeader hwcfg;
Steven Toth443c12282009-05-09 21:17:28 -0300350
351 /* hardware specific registers */
352 u32 bufcounter;
353 u32 pitch;
354 u32 bufsize;
355 u32 bufoffset;
356 u32 bufptr32l;
357 u32 bufptr32h;
358 u64 bufptr64;
359
360 u32 numpte; /* Number of entries in array, only valid in head */
Steven Tothadd3f582010-07-31 14:43:07 -0300361
Steven Toth443c12282009-05-09 21:17:28 -0300362 struct mutex dmaqueue_lock;
Steven Toth443c12282009-05-09 21:17:28 -0300363 struct saa7164_buffer dmaqueue;
Steven Tothadd3f582010-07-31 14:43:07 -0300364
Steven Toth91d80182010-07-31 14:46:51 -0300365 u64 last_irq_msecs, last_svc_msecs;
366 u64 last_irq_msecs_diff, last_svc_msecs_diff;
Steven Tothcfbaf332010-07-31 15:49:28 -0300367 u32 last_svc_wp;
368 u32 last_svc_rp;
Steven Toth91d80182010-07-31 14:46:51 -0300369 u64 last_irq_svc_msecs_diff;
Steven Toth58acca12010-07-31 15:10:52 -0300370 u64 last_read_msecs, last_read_msecs_diff;
371 u64 last_poll_msecs, last_poll_msecs_diff;
Steven Toth91d80182010-07-31 14:46:51 -0300372
373 struct saa7164_histogram irq_interval;
374 struct saa7164_histogram svc_interval;
375 struct saa7164_histogram irq_svc_interval;
Steven Toth58acca12010-07-31 15:10:52 -0300376 struct saa7164_histogram read_interval;
377 struct saa7164_histogram poll_interval;
Steven Toth91d80182010-07-31 14:46:51 -0300378
Steven Tothadd3f582010-07-31 14:43:07 -0300379 /* --- DVB Transport Specific --- */
380 struct saa7164_dvb dvb;
381
382 /* --- Encoder/V4L related attributes --- */
Steven Toth7615e432010-07-31 14:44:53 -0300383 /* Encoder */
384 /* Defaults established in saa7164-encoder.c */
385 struct saa7164_tvnorm encodernorm;
386 u32 height;
387 u32 width;
388 u32 freq;
389 u32 ts_packet_size;
390 u32 ts_packet_count;
391 u8 mux_input;
392 u8 encoder_profile;
393 u8 video_format;
394 u8 audio_format;
395 u8 video_resolution;
396 u16 ctl_brightness;
397 u16 ctl_contrast;
398 u16 ctl_hue;
399 u16 ctl_saturation;
400 u16 ctl_sharpness;
401 s8 ctl_volume;
Steven Toth443c12282009-05-09 21:17:28 -0300402
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300403 struct tmComResAFeatureDescrHeader audfeat;
404 struct tmComResEncoderDescrHeader encunit;
405 struct tmComResProcDescrHeader vidproc;
406 struct tmComResExtDevDescrHeader ifunit;
407 struct tmComResTunerDescrHeader tunerunit;
Steven Toth7615e432010-07-31 14:44:53 -0300408
Steven Toth91d80182010-07-31 14:46:51 -0300409 struct work_struct workenc;
410
Steven Tothe8ce2f22010-07-31 16:06:06 -0300411 /* V4L Encoder Video */
Steven Toth7615e432010-07-31 14:44:53 -0300412 struct saa7164_encoder_params encoder_params;
413 struct video_device *v4l_device;
414 atomic_t v4l_reader_count;
Steven Toth7615e432010-07-31 14:44:53 -0300415
416 struct saa7164_buffer list_buf_used;
417 struct saa7164_buffer list_buf_free;
418 wait_queue_head_t wait_read;
Steven Toth9230aca2010-07-31 15:06:49 -0300419
Steven Tothe8ce2f22010-07-31 16:06:06 -0300420 /* V4L VBI */
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300421 struct tmComResVBIFormatDescrHeader vbi_fmt_ntsc;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300422 struct saa7164_vbi_params vbi_params;
423
Steven Toth9230aca2010-07-31 15:06:49 -0300424 /* Debug */
425 u32 sync_errors;
426 u32 v_cc_errors;
427 u32 a_cc_errors;
428 u8 last_v_cc;
429 u8 last_a_cc;
Steven Toth1b0e8e42010-07-31 16:01:00 -0300430 u32 done_first_interrupt;
Steven Toth443c12282009-05-09 21:17:28 -0300431};
432
433struct saa7164_dev {
434 struct list_head devlist;
435 atomic_t refcount;
436
437 /* pci stuff */
438 struct pci_dev *pci;
439 unsigned char pci_rev, pci_lat;
440 int pci_bus, pci_slot;
441 u32 __iomem *lmmio;
442 u8 __iomem *bmmio;
443 u32 __iomem *lmmio2;
444 u8 __iomem *bmmio2;
445 int pci_irqmask;
446
447 /* board details */
448 int nr;
449 int hwrevision;
450 u32 board;
451 char name[32];
452
453 /* firmware status */
454 struct saa7164_fw_status fw_status;
Steven Toth22760ed2010-09-05 11:24:50 -0300455 u32 firmwareloaded;
Steven Toth443c12282009-05-09 21:17:28 -0300456
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300457 struct tmComResHWDescr hwdesc;
458 struct tmComResInterfaceDescr intfdesc;
459 struct tmComResBusDescr busdesc;
Steven Toth443c12282009-05-09 21:17:28 -0300460
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300461 struct tmComResBusInfo bus;
Steven Toth443c12282009-05-09 21:17:28 -0300462
Steven Toth1a6450d2009-05-10 14:08:27 -0300463 /* Interrupt status and ack registers */
464 u32 int_status;
465 u32 int_ack;
Steven Toth443c12282009-05-09 21:17:28 -0300466
467 struct cmd cmds[SAA_CMD_MAX_MSG_UNITS];
468 struct mutex lock;
469
470 /* I2c related */
471 struct saa7164_i2c i2c_bus[3];
472
473 /* Transport related */
Mauro Carvalho Chehabc7e242ba2010-10-11 17:39:06 -0300474 struct saa7164_port ports[SAA7164_MAX_PORTS];
Steven Toth443c12282009-05-09 21:17:28 -0300475
476 /* Deferred command/api interrupts handling */
477 struct work_struct workcmd;
478
Steven Toth0b62ceb2010-07-31 16:17:51 -0300479 /* A kernel thread to monitor the firmware log, used
480 * only in debug mode.
481 */
482 struct task_struct *kthread;
483
Steven Toth443c12282009-05-09 21:17:28 -0300484};
485
486extern struct list_head saa7164_devlist;
Steven Tothdd1ee442009-07-30 09:09:30 -0300487extern unsigned int waitsecs;
Steven Toth66e1d372010-07-31 15:09:25 -0300488extern unsigned int encoder_buffers;
Steven Tothe8ce2f22010-07-31 16:06:06 -0300489extern unsigned int vbi_buffers;
Steven Toth443c12282009-05-09 21:17:28 -0300490
491/* ----------------------------------------------------------- */
492/* saa7164-core.c */
493void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
494void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len);
495void saa7164_getfirmwarestatus(struct saa7164_dev *dev);
496u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev);
Steven Toth58acca12010-07-31 15:10:52 -0300497void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val);
Steven Toth443c12282009-05-09 21:17:28 -0300498
499/* ----------------------------------------------------------- */
500/* saa7164-fw.c */
501int saa7164_downloadfirmware(struct saa7164_dev *dev);
502
503/* ----------------------------------------------------------- */
504/* saa7164-i2c.c */
505extern int saa7164_i2c_register(struct saa7164_i2c *bus);
506extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);
507extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
508 unsigned int cmd, void *arg);
509
510/* ----------------------------------------------------------- */
511/* saa7164-bus.c */
512int saa7164_bus_setup(struct saa7164_dev *dev);
513void saa7164_bus_dump(struct saa7164_dev *dev);
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300514int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf);
515int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
Steven Toth443c12282009-05-09 21:17:28 -0300516 void *buf, int peekonly);
517
518/* ----------------------------------------------------------- */
519/* saa7164-cmd.c */
520int saa7164_cmd_send(struct saa7164_dev *dev,
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300521 u8 id, enum tmComResCmd command, u16 controlselector,
Steven Toth443c12282009-05-09 21:17:28 -0300522 u16 size, void *buf);
523void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
Steven Toth39e469a2009-08-12 12:14:37 -0300524int saa7164_irq_dequeue(struct saa7164_dev *dev);
Steven Toth443c12282009-05-09 21:17:28 -0300525
526/* ----------------------------------------------------------- */
527/* saa7164-api.c */
Steven Toth443c12282009-05-09 21:17:28 -0300528int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version);
529int saa7164_api_enum_subdevs(struct saa7164_dev *dev);
530int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
531 u32 datalen, u8 *data);
532int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr,
533 u32 datalen, u8 *data);
534int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr,
535 u32 datalen, u8 *data);
536int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
537int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
538int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
Steven Tothadd3f582010-07-31 14:43:07 -0300539int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
Steven Toth7615e432010-07-31 14:44:53 -0300540int saa7164_api_initialize_dif(struct saa7164_port *port);
541int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
542int saa7164_api_set_encoder(struct saa7164_port *port);
543int saa7164_api_get_encoder(struct saa7164_port *port);
544int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
545int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
546int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
547int saa7164_api_set_videomux(struct saa7164_port *port);
548int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
549int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
550int saa7164_api_set_audio_std(struct saa7164_port *port);
551int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
552int saa7164_api_get_videomux(struct saa7164_port *port);
Steven Tothe8ce2f22010-07-31 16:06:06 -0300553int saa7164_api_set_vbi_format(struct saa7164_port *port);
Steven Tothe48836b2010-07-31 16:08:52 -0300554int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level);
Steven Toth0b62ceb2010-07-31 16:17:51 -0300555int saa7164_api_collect_debug(struct saa7164_dev *dev);
Mauro Carvalho Chehab4d270cf2010-10-11 17:17:45 -0300556int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i);
Steven Toth443c12282009-05-09 21:17:28 -0300557
558/* ----------------------------------------------------------- */
559/* saa7164-cards.c */
560extern struct saa7164_board saa7164_boards[];
561extern const unsigned int saa7164_bcount;
562
563extern struct saa7164_subid saa7164_subids[];
564extern const unsigned int saa7164_idcount;
565
566extern void saa7164_card_list(struct saa7164_dev *dev);
567extern void saa7164_gpio_setup(struct saa7164_dev *dev);
568extern void saa7164_card_setup(struct saa7164_dev *dev);
569
570extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
571extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
572extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);
573
574/* ----------------------------------------------------------- */
575/* saa7164-dvb.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300576extern int saa7164_dvb_register(struct saa7164_port *port);
577extern int saa7164_dvb_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300578
579/* ----------------------------------------------------------- */
580/* saa7164-buffer.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300581extern struct saa7164_buffer *saa7164_buffer_alloc(
582 struct saa7164_port *port, u32 len);
583extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
584extern void saa7164_buffer_display(struct saa7164_buffer *buf);
585extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
586extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
Steven Toth7615e432010-07-31 14:44:53 -0300587extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
588 struct saa7164_dev *dev, u32 len);
589extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
Steven Toth9230aca2010-07-31 15:06:49 -0300590extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);
Steven Toth7615e432010-07-31 14:44:53 -0300591
Steven Toth7615e432010-07-31 14:44:53 -0300592/* ----------------------------------------------------------- */
593/* saa7164-encoder.c */
594int saa7164_encoder_register(struct saa7164_port *port);
595void saa7164_encoder_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300596
597/* ----------------------------------------------------------- */
Steven Tothe8ce2f22010-07-31 16:06:06 -0300598/* saa7164-vbi.c */
599int saa7164_vbi_register(struct saa7164_port *port);
600void saa7164_vbi_unregister(struct saa7164_port *port);
601
602/* ----------------------------------------------------------- */
Steven Toth443c12282009-05-09 21:17:28 -0300603
Steven Toth1b0e8e42010-07-31 16:01:00 -0300604extern unsigned int crc_checking;
605
Ingo Molnarb1912a852009-09-21 15:23:45 -0300606extern unsigned int saa_debug;
Steven Toth443c12282009-05-09 21:17:28 -0300607#define dprintk(level, fmt, arg...)\
Ingo Molnarb1912a852009-09-21 15:23:45 -0300608 do { if (saa_debug & level)\
Steven Toth443c12282009-05-09 21:17:28 -0300609 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
610 } while (0)
611
612#define log_warn(fmt, arg...)\
613 do { \
614 printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\
615 } while (0)
616
617#define log_err(fmt, arg...)\
618 do { \
619 printk(KERN_ERROR "%s: " fmt, dev->name, ## arg);\
620 } while (0)
621
622#define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2))
Steven Toth207b42c2009-05-09 21:30:05 -0300623#define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
624
Steven Toth443c12282009-05-09 21:17:28 -0300625#define saa7164_readb(reg) readl(dev->bmmio + (reg))
626#define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg))
627