blob: a8a29e56b2cef2a217b9bc28224921d5665a9473 [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 Toth443c12282009-05-09 21:17:28 -030054
55#include <media/tuner.h>
56#include <media/tveeprom.h>
57#include <media/videobuf-dma-sg.h>
58#include <media/videobuf-dvb.h>
Steven Toth7615e432010-07-31 14:44:53 -030059#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 Toth443c12282009-05-09 21:17:28 -030068
69#include "saa7164-reg.h"
70#include "saa7164-types.h"
71
Steven Toth443c12282009-05-09 21:17:28 -030072#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 Tothe3335222009-05-11 22:03:07 -030084#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
Steven Toth443c12282009-05-09 21:17:28 -030085
86#define SAA7164_MAX_UNITS 8
87#define SAA7164_TS_NUMBER_OF_LINES 312
88#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
Steven Toth66e1d372010-07-31 15:09:25 -030089#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
Steven Toth7615e432010-07-31 14:44:53 -030090
91/* Port related defines */
92#define SAA7164_PORT_TS1 (0)
93#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
94#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
95#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
96#define SAA7164_MAX_PORTS (SAA7164_PORT_ENC2 + 1)
Steven Toth443c12282009-05-09 21:17:28 -030097
98#define DBGLVL_FW 4
99#define DBGLVL_DVB 8
100#define DBGLVL_I2C 16
101#define DBGLVL_API 32
102#define DBGLVL_CMD 64
103#define DBGLVL_BUS 128
104#define DBGLVL_IRQ 256
105#define DBGLVL_BUF 512
Steven Toth9b8b0192010-07-31 14:39:44 -0300106#define DBGLVL_ENC 1024
Steven Toth443c12282009-05-09 21:17:28 -0300107
Steven Toth7615e432010-07-31 14:44:53 -0300108#define SAA7164_NORMS ( V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 )
109
Steven Toth443c12282009-05-09 21:17:28 -0300110enum port_t {
111 SAA7164_MPEG_UNDEFINED = 0,
112 SAA7164_MPEG_DVB,
Steven Tothadd3f582010-07-31 14:43:07 -0300113 SAA7164_MPEG_ENCODER,
Steven Toth443c12282009-05-09 21:17:28 -0300114};
115
116enum saa7164_i2c_bus_nr {
117 SAA7164_I2C_BUS_0 = 0,
118 SAA7164_I2C_BUS_1,
119 SAA7164_I2C_BUS_2,
120};
121
122enum saa7164_buffer_flags {
123 SAA7164_BUFFER_UNDEFINED = 0,
124 SAA7164_BUFFER_FREE,
125 SAA7164_BUFFER_BUSY,
126 SAA7164_BUFFER_FULL
127};
128
129enum saa7164_unit_type {
130 SAA7164_UNIT_UNDEFINED = 0,
131 SAA7164_UNIT_DIGITAL_DEMODULATOR,
132 SAA7164_UNIT_ANALOG_DEMODULATOR,
133 SAA7164_UNIT_TUNER,
134 SAA7164_UNIT_EEPROM,
135 SAA7164_UNIT_ZILOG_IRBLASTER,
136 SAA7164_UNIT_ENCODER,
137};
138
139/* The PCIe bridge doesn't grant direct access to i2c.
140 * Instead, you address i2c devices using a uniqely
141 * allocated 'unitid' value via a messaging API. This
142 * is a problem. The kernel and existing demod/tuner
143 * drivers expect to talk 'i2c', so we have to maintain
144 * a translation layer, and a series of functions to
145 * convert i2c bus + device address into a unit id.
146 */
147struct saa7164_unit {
148 enum saa7164_unit_type type;
149 u8 id;
150 char *name;
151 enum saa7164_i2c_bus_nr i2c_bus_nr;
152 u8 i2c_bus_addr;
153 u8 i2c_reg_len;
154};
155
156struct saa7164_board {
157 char *name;
Steven Toth7615e432010-07-31 14:44:53 -0300158 enum port_t porta, portb, portc, portd;
Steven Toth443c12282009-05-09 21:17:28 -0300159 enum {
160 SAA7164_CHIP_UNDEFINED = 0,
161 SAA7164_CHIP_REV2,
162 SAA7164_CHIP_REV3,
163 } chiprev;
164 struct saa7164_unit unit[SAA7164_MAX_UNITS];
165};
166
167struct saa7164_subid {
168 u16 subvendor;
169 u16 subdevice;
170 u32 card;
171};
172
Steven Toth7615e432010-07-31 14:44:53 -0300173struct saa7164_fh {
174 struct saa7164_port *port;
175 u32 freq;
176 u32 tuner_type;
177 atomic_t v4l_reading;
178};
179
Steven Toth91d80182010-07-31 14:46:51 -0300180struct saa7164_histogram_bucket {
181 u32 val;
182 u32 count;
183 u64 update_time;
184};
185
186struct saa7164_histogram {
187 char name[32];
188 struct saa7164_histogram_bucket counter1[64];
189};
190
Steven Toth7615e432010-07-31 14:44:53 -0300191struct saa7164_user_buffer {
192 struct list_head list;
193
194 /* Attributes */
195 u8 *data;
196 u32 pos;
197 u32 actual_size;
Steven Toth12d32032010-07-31 15:13:45 -0300198
199 u32 crc;
Steven Toth7615e432010-07-31 14:44:53 -0300200};
201
Steven Toth443c12282009-05-09 21:17:28 -0300202struct saa7164_fw_status {
203
204 /* RISC Core details */
205 u32 status;
206 u32 mode;
207 u32 spec;
208 u32 inst;
209 u32 cpuload;
210 u32 remainheap;
211
212 /* Firmware version */
213 u32 version;
214 u32 major;
215 u32 sub;
216 u32 rel;
217 u32 buildnr;
218};
219
220struct saa7164_dvb {
221 struct mutex lock;
222 struct dvb_adapter adapter;
223 struct dvb_frontend *frontend;
224 struct dvb_demux demux;
225 struct dmxdev dmxdev;
226 struct dmx_frontend fe_hw;
227 struct dmx_frontend fe_mem;
228 struct dvb_net net;
229 int feeding;
230};
231
232struct saa7164_i2c {
233 struct saa7164_dev *dev;
234
235 enum saa7164_i2c_bus_nr nr;
236
237 /* I2C I/O */
238 struct i2c_adapter i2c_adap;
239 struct i2c_algo_bit_data i2c_algo;
240 struct i2c_client i2c_client;
241 u32 i2c_rc;
242};
243
Steven Toth7615e432010-07-31 14:44:53 -0300244struct saa7164_ctrl {
245 struct v4l2_queryctrl v;
246};
247
248struct saa7164_tvnorm {
249 char *name;
250 v4l2_std_id id;
251// u32 cxiformat;
252// u32 cxoformat;
253};
254
255struct saa7164_encoder_params {
256 struct saa7164_tvnorm encodernorm;
257 u32 height;
258 u32 width;
259 u32 is_50hz;
260 u32 bitrate; /* bps */
Steven Toth968b11b2010-07-31 14:59:38 -0300261 u32 bitrate_peak; /* bps */
Steven Toth2600d712010-07-31 14:51:30 -0300262 u32 bitrate_mode;
Steven Toth7615e432010-07-31 14:44:53 -0300263 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
264
265 u32 audio_sampling_freq;
266 u32 ctl_mute;
267 u32 ctl_aspect;
Steven Toth3ed43cf2010-07-31 14:58:35 -0300268 u32 refdist;
Steven Toth5fa56cc2010-07-31 15:05:35 -0300269 u32 gop_size;
Steven Toth7615e432010-07-31 14:44:53 -0300270};
271
Steven Tothadd3f582010-07-31 14:43:07 -0300272struct saa7164_port;
Steven Toth443c12282009-05-09 21:17:28 -0300273
274struct saa7164_buffer {
275 struct list_head list;
276
Steven Tothadd3f582010-07-31 14:43:07 -0300277 /* Note of which h/w buffer list index position we occupy */
278 int idx;
Steven Toth443c12282009-05-09 21:17:28 -0300279
Steven Tothadd3f582010-07-31 14:43:07 -0300280 struct saa7164_port *port;
Steven Toth443c12282009-05-09 21:17:28 -0300281
282 /* Hardware Specific */
283 /* PCI Memory allocations */
284 enum saa7164_buffer_flags flags; /* Free, Busy, Full */
285
286 /* A block of page align PCI memory */
287 u32 pci_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300288 u64 __iomem *cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300289 dma_addr_t dma; /* Physical address */
Steven Toth12d32032010-07-31 15:13:45 -0300290 u32 crc; /* Checksum for the entire buffer data */
Steven Toth443c12282009-05-09 21:17:28 -0300291
292 /* A page table that splits the block into a number of entries */
293 u32 pt_size; /* PCI allocation size in bytes */
Steven Toth12d32032010-07-31 15:13:45 -0300294 u64 __iomem *pt_cpu; /* Virtual address */
Steven Toth443c12282009-05-09 21:17:28 -0300295 dma_addr_t pt_dma; /* Physical address */
Steven Tothadd3f582010-07-31 14:43:07 -0300296
297 /* Encoder fops */
298 u32 pos;
299 u32 actual_size;
Steven Toth443c12282009-05-09 21:17:28 -0300300};
301
Steven Tothadd3f582010-07-31 14:43:07 -0300302struct saa7164_port {
Steven Toth443c12282009-05-09 21:17:28 -0300303
304 struct saa7164_dev *dev;
Steven Toth443c12282009-05-09 21:17:28 -0300305 enum port_t type;
Steven Tothadd3f582010-07-31 14:43:07 -0300306 int nr;
Steven Toth443c12282009-05-09 21:17:28 -0300307
Steven Tothadd3f582010-07-31 14:43:07 -0300308 /* --- Generic port attributes --- */
Steven Toth443c12282009-05-09 21:17:28 -0300309
Steven Tothadd3f582010-07-31 14:43:07 -0300310 /* HW stream parameters */
Steven Toth443c12282009-05-09 21:17:28 -0300311 tmHWStreamParameters_t hw_streamingparams;
312
313 /* DMA configuration values, is seeded during initialization */
314 tmComResDMATermDescrHeader_t hwcfg;
315
316 /* hardware specific registers */
317 u32 bufcounter;
318 u32 pitch;
319 u32 bufsize;
320 u32 bufoffset;
321 u32 bufptr32l;
322 u32 bufptr32h;
323 u64 bufptr64;
324
325 u32 numpte; /* Number of entries in array, only valid in head */
Steven Tothadd3f582010-07-31 14:43:07 -0300326
Steven Toth443c12282009-05-09 21:17:28 -0300327 struct mutex dmaqueue_lock;
Steven Toth443c12282009-05-09 21:17:28 -0300328 struct saa7164_buffer dmaqueue;
Steven Tothadd3f582010-07-31 14:43:07 -0300329
Steven Toth91d80182010-07-31 14:46:51 -0300330 u64 last_irq_msecs, last_svc_msecs;
331 u64 last_irq_msecs_diff, last_svc_msecs_diff;
332 u32 last_irq_wp, last_svc_wp;
333 u32 last_irq_rp, last_svc_rp;
334 u64 last_irq_svc_msecs_diff;
Steven Toth58acca12010-07-31 15:10:52 -0300335 u64 last_read_msecs, last_read_msecs_diff;
336 u64 last_poll_msecs, last_poll_msecs_diff;
Steven Toth91d80182010-07-31 14:46:51 -0300337
338 struct saa7164_histogram irq_interval;
339 struct saa7164_histogram svc_interval;
340 struct saa7164_histogram irq_svc_interval;
Steven Toth58acca12010-07-31 15:10:52 -0300341 struct saa7164_histogram read_interval;
342 struct saa7164_histogram poll_interval;
Steven Toth91d80182010-07-31 14:46:51 -0300343
Steven Tothadd3f582010-07-31 14:43:07 -0300344 /* --- DVB Transport Specific --- */
345 struct saa7164_dvb dvb;
346
347 /* --- Encoder/V4L related attributes --- */
Steven Toth7615e432010-07-31 14:44:53 -0300348 /* Encoder */
349 /* Defaults established in saa7164-encoder.c */
350 struct saa7164_tvnorm encodernorm;
351 u32 height;
352 u32 width;
353 u32 freq;
354 u32 ts_packet_size;
355 u32 ts_packet_count;
356 u8 mux_input;
357 u8 encoder_profile;
358 u8 video_format;
359 u8 audio_format;
360 u8 video_resolution;
361 u16 ctl_brightness;
362 u16 ctl_contrast;
363 u16 ctl_hue;
364 u16 ctl_saturation;
365 u16 ctl_sharpness;
366 s8 ctl_volume;
Steven Toth443c12282009-05-09 21:17:28 -0300367
Steven Toth7615e432010-07-31 14:44:53 -0300368 tmComResAFeatureDescrHeader_t audfeat;
369 tmComResEncoderDescrHeader_t encunit;
370 tmComResProcDescrHeader_t vidproc;
371 tmComResExtDevDescrHeader_t ifunit;
372 tmComResTunerDescrHeader_t tunerunit;
373
Steven Toth91d80182010-07-31 14:46:51 -0300374 struct work_struct workenc;
375
Steven Toth7615e432010-07-31 14:44:53 -0300376 /* V4L */
377 struct saa7164_encoder_params encoder_params;
378 struct video_device *v4l_device;
379 atomic_t v4l_reader_count;
380// spinlock_t slock;
381// struct mutex fops_lock;
382
383 struct saa7164_buffer list_buf_used;
384 struct saa7164_buffer list_buf_free;
385 wait_queue_head_t wait_read;
Steven Toth9230aca2010-07-31 15:06:49 -0300386
387 /* Debug */
388 u32 sync_errors;
389 u32 v_cc_errors;
390 u32 a_cc_errors;
391 u8 last_v_cc;
392 u8 last_a_cc;
Steven Toth12d32032010-07-31 15:13:45 -0300393
394 u8 *shadow_buf[8];
395 u32 shadow_crc[8];
Steven Toth443c12282009-05-09 21:17:28 -0300396};
397
398struct saa7164_dev {
399 struct list_head devlist;
400 atomic_t refcount;
401
402 /* pci stuff */
403 struct pci_dev *pci;
404 unsigned char pci_rev, pci_lat;
405 int pci_bus, pci_slot;
406 u32 __iomem *lmmio;
407 u8 __iomem *bmmio;
408 u32 __iomem *lmmio2;
409 u8 __iomem *bmmio2;
410 int pci_irqmask;
411
412 /* board details */
413 int nr;
414 int hwrevision;
415 u32 board;
416 char name[32];
417
418 /* firmware status */
419 struct saa7164_fw_status fw_status;
420
421 tmComResHWDescr_t hwdesc;
422 tmComResInterfaceDescr_t intfdesc;
423 tmComResBusDescr_t busdesc;
424
425 tmComResBusInfo_t bus;
426
Steven Toth1a6450d2009-05-10 14:08:27 -0300427 /* Interrupt status and ack registers */
428 u32 int_status;
429 u32 int_ack;
Steven Toth443c12282009-05-09 21:17:28 -0300430
431 struct cmd cmds[SAA_CMD_MAX_MSG_UNITS];
432 struct mutex lock;
433
434 /* I2c related */
435 struct saa7164_i2c i2c_bus[3];
436
437 /* Transport related */
Steven Toth7615e432010-07-31 14:44:53 -0300438 struct saa7164_port ports[ SAA7164_MAX_PORTS ];
Steven Toth443c12282009-05-09 21:17:28 -0300439
440 /* Deferred command/api interrupts handling */
441 struct work_struct workcmd;
442
443};
444
445extern struct list_head saa7164_devlist;
Steven Tothdd1ee442009-07-30 09:09:30 -0300446extern unsigned int waitsecs;
Steven Toth66e1d372010-07-31 15:09:25 -0300447extern unsigned int encoder_buffers;
Steven Toth443c12282009-05-09 21:17:28 -0300448
449/* ----------------------------------------------------------- */
450/* saa7164-core.c */
451void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
452void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len);
453void saa7164_getfirmwarestatus(struct saa7164_dev *dev);
454u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev);
Steven Toth58acca12010-07-31 15:10:52 -0300455void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val);
Steven Toth443c12282009-05-09 21:17:28 -0300456
457/* ----------------------------------------------------------- */
458/* saa7164-fw.c */
459int saa7164_downloadfirmware(struct saa7164_dev *dev);
460
461/* ----------------------------------------------------------- */
462/* saa7164-i2c.c */
463extern int saa7164_i2c_register(struct saa7164_i2c *bus);
464extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);
465extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
466 unsigned int cmd, void *arg);
467
468/* ----------------------------------------------------------- */
469/* saa7164-bus.c */
470int saa7164_bus_setup(struct saa7164_dev *dev);
471void saa7164_bus_dump(struct saa7164_dev *dev);
472int saa7164_bus_set(struct saa7164_dev *dev, tmComResInfo_t* msg, void *buf);
473int saa7164_bus_get(struct saa7164_dev *dev, tmComResInfo_t* msg,
474 void *buf, int peekonly);
475
476/* ----------------------------------------------------------- */
477/* saa7164-cmd.c */
478int saa7164_cmd_send(struct saa7164_dev *dev,
479 u8 id, tmComResCmd_t command, u16 controlselector,
480 u16 size, void *buf);
481void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
Steven Toth39e469a2009-08-12 12:14:37 -0300482int saa7164_irq_dequeue(struct saa7164_dev *dev);
Steven Toth443c12282009-05-09 21:17:28 -0300483
484/* ----------------------------------------------------------- */
485/* saa7164-api.c */
Steven Toth443c12282009-05-09 21:17:28 -0300486int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version);
487int saa7164_api_enum_subdevs(struct saa7164_dev *dev);
488int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
489 u32 datalen, u8 *data);
490int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr,
491 u32 datalen, u8 *data);
492int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr,
493 u32 datalen, u8 *data);
494int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
495int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
496int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
Steven Tothadd3f582010-07-31 14:43:07 -0300497int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
Steven Toth7615e432010-07-31 14:44:53 -0300498int saa7164_api_initialize_dif(struct saa7164_port *port);
499int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
500int saa7164_api_set_encoder(struct saa7164_port *port);
501int saa7164_api_get_encoder(struct saa7164_port *port);
502int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
503int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
504int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
505int saa7164_api_set_videomux(struct saa7164_port *port);
506int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
507int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
508int saa7164_api_set_audio_std(struct saa7164_port *port);
509int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
510int saa7164_api_get_videomux(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300511
512/* ----------------------------------------------------------- */
513/* saa7164-cards.c */
514extern struct saa7164_board saa7164_boards[];
515extern const unsigned int saa7164_bcount;
516
517extern struct saa7164_subid saa7164_subids[];
518extern const unsigned int saa7164_idcount;
519
520extern void saa7164_card_list(struct saa7164_dev *dev);
521extern void saa7164_gpio_setup(struct saa7164_dev *dev);
522extern void saa7164_card_setup(struct saa7164_dev *dev);
523
524extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
525extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
526extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);
527
528/* ----------------------------------------------------------- */
529/* saa7164-dvb.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300530extern int saa7164_dvb_register(struct saa7164_port *port);
531extern int saa7164_dvb_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300532
533/* ----------------------------------------------------------- */
534/* saa7164-buffer.c */
Steven Tothadd3f582010-07-31 14:43:07 -0300535extern struct saa7164_buffer *saa7164_buffer_alloc(
536 struct saa7164_port *port, u32 len);
537extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
538extern void saa7164_buffer_display(struct saa7164_buffer *buf);
539extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
540extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
Steven Toth7615e432010-07-31 14:44:53 -0300541extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
542 struct saa7164_dev *dev, u32 len);
543extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
Steven Toth9230aca2010-07-31 15:06:49 -0300544extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);
Steven Toth7615e432010-07-31 14:44:53 -0300545
Steven Toth7615e432010-07-31 14:44:53 -0300546/* ----------------------------------------------------------- */
547/* saa7164-encoder.c */
548int saa7164_encoder_register(struct saa7164_port *port);
549void saa7164_encoder_unregister(struct saa7164_port *port);
Steven Toth443c12282009-05-09 21:17:28 -0300550
551/* ----------------------------------------------------------- */
552
Ingo Molnarb1912a852009-09-21 15:23:45 -0300553extern unsigned int saa_debug;
Steven Toth443c12282009-05-09 21:17:28 -0300554#define dprintk(level, fmt, arg...)\
Ingo Molnarb1912a852009-09-21 15:23:45 -0300555 do { if (saa_debug & level)\
Steven Toth443c12282009-05-09 21:17:28 -0300556 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
557 } while (0)
558
559#define log_warn(fmt, arg...)\
560 do { \
561 printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\
562 } while (0)
563
564#define log_err(fmt, arg...)\
565 do { \
566 printk(KERN_ERROR "%s: " fmt, dev->name, ## arg);\
567 } while (0)
568
569#define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2))
Steven Toth207b42c2009-05-09 21:30:05 -0300570#define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
571
Steven Toth443c12282009-05-09 21:17:28 -0300572
573#define saa7164_readb(reg) readl(dev->bmmio + (reg))
574#define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg))
575