saa7164.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Driver for the NXP SAA7164 PCIe bridge
  3. *
  4. * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
  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. Driver architecture
  23. *******************
  24. saa7164_core.c/buffer.c/cards.c/i2c.c/dvb.c
  25. | : Standard Linux driver framework for creating
  26. | : exposing and managing interfaces to the rest
  27. | : of the kernel or userland. Also uses _fw.c to load
  28. | : firmware direct into the PCIe bus, bypassing layers.
  29. V
  30. saa7164_api..() : Translate kernel specific functions/features
  31. | : into command buffers.
  32. V
  33. saa7164_cmd..() : Manages the flow of command packets on/off,
  34. | : the bus. Deal with bus errors, timeouts etc.
  35. V
  36. saa7164_bus..() : Manage a read/write memory ring buffer in the
  37. | : PCIe Address space.
  38. |
  39. | saa7164_fw...() : Load any frimware
  40. | | : direct into the device
  41. V V
  42. <- ----------------- PCIe address space -------------------- ->
  43. */
  44. #include <linux/pci.h>
  45. #include <linux/i2c.h>
  46. #include <linux/kdev_t.h>
  47. #include <linux/mutex.h>
  48. #include <linux/crc32.h>
  49. #include <linux/kthread.h>
  50. #include <linux/freezer.h>
  51. #include <media/tuner.h>
  52. #include <media/tveeprom.h>
  53. #include <dvb_demux.h>
  54. #include <dvb_frontend.h>
  55. #include <dvb_net.h>
  56. #include <dvbdev.h>
  57. #include <dmxdev.h>
  58. #include <media/v4l2-common.h>
  59. #include <media/v4l2-ioctl.h>
  60. #include <media/v4l2-device.h>
  61. #include <media/v4l2-ctrls.h>
  62. #include <media/v4l2-event.h>
  63. #include "saa7164-reg.h"
  64. #include "saa7164-types.h"
  65. #define SAA7164_MAXBOARDS 8
  66. #define UNSET (-1U)
  67. #define SAA7164_BOARD_NOAUTO UNSET
  68. #define SAA7164_BOARD_UNKNOWN 0
  69. #define SAA7164_BOARD_UNKNOWN_REV2 1
  70. #define SAA7164_BOARD_UNKNOWN_REV3 2
  71. #define SAA7164_BOARD_HAUPPAUGE_HVR2250 3
  72. #define SAA7164_BOARD_HAUPPAUGE_HVR2200 4
  73. #define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5
  74. #define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6
  75. #define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7
  76. #define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
  77. #define SAA7164_BOARD_HAUPPAUGE_HVR2200_4 9
  78. #define SAA7164_BOARD_HAUPPAUGE_HVR2200_5 10
  79. #define SAA7164_BOARD_HAUPPAUGE_HVR2255proto 11
  80. #define SAA7164_BOARD_HAUPPAUGE_HVR2255 12
  81. #define SAA7164_BOARD_HAUPPAUGE_HVR2205 13
  82. #define SAA7164_MAX_UNITS 8
  83. #define SAA7164_TS_NUMBER_OF_LINES 312
  84. #define SAA7164_PS_NUMBER_OF_LINES 256
  85. #define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
  86. #define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
  87. #define SAA7164_MAX_VBI_BUFFERS 64
  88. /* Port related defines */
  89. #define SAA7164_PORT_TS1 (0)
  90. #define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
  91. #define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
  92. #define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
  93. #define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1)
  94. #define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1)
  95. #define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1)
  96. #define DBGLVL_FW 4
  97. #define DBGLVL_DVB 8
  98. #define DBGLVL_I2C 16
  99. #define DBGLVL_API 32
  100. #define DBGLVL_CMD 64
  101. #define DBGLVL_BUS 128
  102. #define DBGLVL_IRQ 256
  103. #define DBGLVL_BUF 512
  104. #define DBGLVL_ENC 1024
  105. #define DBGLVL_VBI 2048
  106. #define DBGLVL_THR 4096
  107. #define DBGLVL_CPU 8192
  108. #define SAA7164_NORMS \
  109. (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP)
  110. /* TV frequency range copied from tuner-core.c */
  111. #define SAA7164_TV_MIN_FREQ (44U * 16U)
  112. #define SAA7164_TV_MAX_FREQ (958U * 16U)
  113. enum port_t {
  114. SAA7164_MPEG_UNDEFINED = 0,
  115. SAA7164_MPEG_DVB,
  116. SAA7164_MPEG_ENCODER,
  117. SAA7164_MPEG_VBI,
  118. };
  119. enum saa7164_i2c_bus_nr {
  120. SAA7164_I2C_BUS_0 = 0,
  121. SAA7164_I2C_BUS_1,
  122. SAA7164_I2C_BUS_2,
  123. };
  124. enum saa7164_buffer_flags {
  125. SAA7164_BUFFER_UNDEFINED = 0,
  126. SAA7164_BUFFER_FREE,
  127. SAA7164_BUFFER_BUSY,
  128. SAA7164_BUFFER_FULL
  129. };
  130. enum saa7164_unit_type {
  131. SAA7164_UNIT_UNDEFINED = 0,
  132. SAA7164_UNIT_DIGITAL_DEMODULATOR,
  133. SAA7164_UNIT_ANALOG_DEMODULATOR,
  134. SAA7164_UNIT_TUNER,
  135. SAA7164_UNIT_EEPROM,
  136. SAA7164_UNIT_ZILOG_IRBLASTER,
  137. SAA7164_UNIT_ENCODER,
  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. */
  147. struct 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. struct saa7164_board {
  156. char *name;
  157. enum port_t porta, portb, portc,
  158. portd, porte, portf;
  159. 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. struct saa7164_subid {
  167. u16 subvendor;
  168. u16 subdevice;
  169. u32 card;
  170. };
  171. struct saa7164_encoder_fh {
  172. struct v4l2_fh fh;
  173. struct saa7164_port *port;
  174. atomic_t v4l_reading;
  175. };
  176. struct saa7164_vbi_fh {
  177. struct v4l2_fh fh;
  178. struct saa7164_port *port;
  179. atomic_t v4l_reading;
  180. };
  181. struct saa7164_histogram_bucket {
  182. u32 val;
  183. u32 count;
  184. u64 update_time;
  185. };
  186. struct saa7164_histogram {
  187. char name[32];
  188. struct saa7164_histogram_bucket counter1[64];
  189. };
  190. struct saa7164_user_buffer {
  191. struct list_head list;
  192. /* Attributes */
  193. u8 *data;
  194. u32 pos;
  195. u32 actual_size;
  196. u32 crc;
  197. };
  198. struct saa7164_fw_status {
  199. /* RISC Core details */
  200. u32 status;
  201. u32 mode;
  202. u32 spec;
  203. u32 inst;
  204. u32 cpuload;
  205. u32 remainheap;
  206. /* Firmware version */
  207. u32 version;
  208. u32 major;
  209. u32 sub;
  210. u32 rel;
  211. u32 buildnr;
  212. };
  213. struct saa7164_dvb {
  214. struct mutex lock;
  215. struct dvb_adapter adapter;
  216. struct dvb_frontend *frontend;
  217. struct dvb_demux demux;
  218. struct dmxdev dmxdev;
  219. struct dmx_frontend fe_hw;
  220. struct dmx_frontend fe_mem;
  221. struct dvb_net net;
  222. int feeding;
  223. };
  224. struct saa7164_i2c {
  225. struct saa7164_dev *dev;
  226. enum saa7164_i2c_bus_nr nr;
  227. /* I2C I/O */
  228. struct i2c_adapter i2c_adap;
  229. struct i2c_client i2c_client;
  230. u32 i2c_rc;
  231. };
  232. struct saa7164_ctrl {
  233. struct v4l2_queryctrl v;
  234. };
  235. struct saa7164_tvnorm {
  236. char *name;
  237. v4l2_std_id id;
  238. };
  239. struct saa7164_encoder_params {
  240. struct saa7164_tvnorm encodernorm;
  241. u32 height;
  242. u32 width;
  243. u32 is_50hz;
  244. u32 bitrate; /* bps */
  245. u32 bitrate_peak; /* bps */
  246. u32 bitrate_mode;
  247. u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
  248. u32 audio_sampling_freq;
  249. u32 ctl_mute;
  250. u32 ctl_aspect;
  251. u32 refdist;
  252. u32 gop_size;
  253. };
  254. struct saa7164_vbi_params {
  255. struct saa7164_tvnorm encodernorm;
  256. u32 height;
  257. u32 width;
  258. u32 is_50hz;
  259. u32 bitrate; /* bps */
  260. u32 bitrate_peak; /* bps */
  261. u32 bitrate_mode;
  262. u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
  263. u32 audio_sampling_freq;
  264. u32 ctl_mute;
  265. u32 ctl_aspect;
  266. u32 refdist;
  267. u32 gop_size;
  268. };
  269. struct saa7164_port;
  270. struct saa7164_buffer {
  271. struct list_head list;
  272. /* Note of which h/w buffer list index position we occupy */
  273. int idx;
  274. struct saa7164_port *port;
  275. /* Hardware Specific */
  276. /* PCI Memory allocations */
  277. enum saa7164_buffer_flags flags; /* Free, Busy, Full */
  278. /* A block of page align PCI memory */
  279. u32 pci_size; /* PCI allocation size in bytes */
  280. u64 *cpu; /* Virtual address */
  281. dma_addr_t dma; /* Physical address */
  282. u32 crc; /* Checksum for the entire buffer data */
  283. /* A page table that splits the block into a number of entries */
  284. u32 pt_size; /* PCI allocation size in bytes */
  285. u64 *pt_cpu; /* Virtual address */
  286. dma_addr_t pt_dma; /* Physical address */
  287. /* Encoder fops */
  288. u32 pos;
  289. u32 actual_size;
  290. };
  291. struct saa7164_port {
  292. struct saa7164_dev *dev;
  293. enum port_t type;
  294. int nr;
  295. /* --- Generic port attributes --- */
  296. /* HW stream parameters */
  297. struct tmHWStreamParameters hw_streamingparams;
  298. /* DMA configuration values, is seeded during initialization */
  299. struct tmComResDMATermDescrHeader hwcfg;
  300. /* hardware specific registers */
  301. u32 bufcounter;
  302. u32 pitch;
  303. u32 bufsize;
  304. u32 bufoffset;
  305. u32 bufptr32l;
  306. u32 bufptr32h;
  307. u64 bufptr64;
  308. u32 numpte; /* Number of entries in array, only valid in head */
  309. struct mutex dmaqueue_lock;
  310. struct saa7164_buffer dmaqueue;
  311. u64 last_irq_msecs, last_svc_msecs;
  312. u64 last_irq_msecs_diff, last_svc_msecs_diff;
  313. u32 last_svc_wp;
  314. u32 last_svc_rp;
  315. u64 last_irq_svc_msecs_diff;
  316. u64 last_read_msecs, last_read_msecs_diff;
  317. u64 last_poll_msecs, last_poll_msecs_diff;
  318. struct saa7164_histogram irq_interval;
  319. struct saa7164_histogram svc_interval;
  320. struct saa7164_histogram irq_svc_interval;
  321. struct saa7164_histogram read_interval;
  322. struct saa7164_histogram poll_interval;
  323. /* --- DVB Transport Specific --- */
  324. struct saa7164_dvb dvb;
  325. struct i2c_client *i2c_client_demod;
  326. struct i2c_client *i2c_client_tuner;
  327. /* --- Encoder/V4L related attributes --- */
  328. /* Encoder */
  329. /* Defaults established in saa7164-encoder.c */
  330. struct saa7164_tvnorm encodernorm;
  331. struct v4l2_ctrl_handler ctrl_handler;
  332. v4l2_std_id std;
  333. u32 height;
  334. u32 width;
  335. u32 freq;
  336. u8 mux_input;
  337. u8 encoder_profile;
  338. u8 video_format;
  339. u8 audio_format;
  340. u8 video_resolution;
  341. u16 ctl_brightness;
  342. u16 ctl_contrast;
  343. u16 ctl_hue;
  344. u16 ctl_saturation;
  345. u16 ctl_sharpness;
  346. s8 ctl_volume;
  347. struct tmComResAFeatureDescrHeader audfeat;
  348. struct tmComResEncoderDescrHeader encunit;
  349. struct tmComResProcDescrHeader vidproc;
  350. struct tmComResExtDevDescrHeader ifunit;
  351. struct tmComResTunerDescrHeader tunerunit;
  352. struct work_struct workenc;
  353. /* V4L Encoder Video */
  354. struct saa7164_encoder_params encoder_params;
  355. struct video_device *v4l_device;
  356. atomic_t v4l_reader_count;
  357. struct saa7164_buffer list_buf_used;
  358. struct saa7164_buffer list_buf_free;
  359. wait_queue_head_t wait_read;
  360. /* V4L VBI */
  361. struct tmComResVBIFormatDescrHeader vbi_fmt_ntsc;
  362. struct saa7164_vbi_params vbi_params;
  363. struct saa7164_port *enc_port;
  364. /* Debug */
  365. u32 sync_errors;
  366. u32 v_cc_errors;
  367. u32 a_cc_errors;
  368. u8 last_v_cc;
  369. u8 last_a_cc;
  370. u32 done_first_interrupt;
  371. };
  372. struct saa7164_dev {
  373. struct list_head devlist;
  374. atomic_t refcount;
  375. struct v4l2_device v4l2_dev;
  376. /* pci stuff */
  377. struct pci_dev *pci;
  378. unsigned char pci_rev, pci_lat;
  379. int pci_bus, pci_slot;
  380. u32 __iomem *lmmio;
  381. u8 __iomem *bmmio;
  382. u32 __iomem *lmmio2;
  383. u8 __iomem *bmmio2;
  384. int pci_irqmask;
  385. /* board details */
  386. int nr;
  387. int hwrevision;
  388. u32 board;
  389. char name[16];
  390. /* firmware status */
  391. struct saa7164_fw_status fw_status;
  392. u32 firmwareloaded;
  393. struct tmComResHWDescr hwdesc;
  394. struct tmComResInterfaceDescr intfdesc;
  395. struct tmComResBusDescr busdesc;
  396. struct tmComResBusInfo bus;
  397. /* Interrupt status and ack registers */
  398. u32 int_status;
  399. u32 int_ack;
  400. bool msi;
  401. struct cmd cmds[SAA_CMD_MAX_MSG_UNITS];
  402. struct mutex lock;
  403. /* I2c related */
  404. struct saa7164_i2c i2c_bus[3];
  405. /* Transport related */
  406. struct saa7164_port ports[SAA7164_MAX_PORTS];
  407. /* Deferred command/api interrupts handling */
  408. struct work_struct workcmd;
  409. /* A kernel thread to monitor the firmware log, used
  410. * only in debug mode.
  411. */
  412. struct task_struct *kthread;
  413. };
  414. extern struct list_head saa7164_devlist;
  415. extern unsigned int waitsecs;
  416. extern unsigned int encoder_buffers;
  417. extern unsigned int vbi_buffers;
  418. /* ----------------------------------------------------------- */
  419. /* saa7164-core.c */
  420. void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
  421. void saa7164_getfirmwarestatus(struct saa7164_dev *dev);
  422. u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev);
  423. void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val);
  424. /* ----------------------------------------------------------- */
  425. /* saa7164-fw.c */
  426. int saa7164_downloadfirmware(struct saa7164_dev *dev);
  427. /* ----------------------------------------------------------- */
  428. /* saa7164-i2c.c */
  429. extern int saa7164_i2c_register(struct saa7164_i2c *bus);
  430. extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);
  431. extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
  432. unsigned int cmd, void *arg);
  433. /* ----------------------------------------------------------- */
  434. /* saa7164-bus.c */
  435. int saa7164_bus_setup(struct saa7164_dev *dev);
  436. void saa7164_bus_dump(struct saa7164_dev *dev);
  437. int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
  438. void *buf);
  439. int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
  440. void *buf, int peekonly);
  441. /* ----------------------------------------------------------- */
  442. /* saa7164-cmd.c */
  443. int saa7164_cmd_send(struct saa7164_dev *dev,
  444. u8 id, enum tmComResCmd command, u16 controlselector,
  445. u16 size, void *buf);
  446. void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
  447. int saa7164_irq_dequeue(struct saa7164_dev *dev);
  448. /* ----------------------------------------------------------- */
  449. /* saa7164-api.c */
  450. int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version);
  451. int saa7164_api_enum_subdevs(struct saa7164_dev *dev);
  452. int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
  453. u32 datalen, u8 *data);
  454. int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr,
  455. u32 datalen, u8 *data);
  456. int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr,
  457. u32 datalen, u8 *data);
  458. int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
  459. int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
  460. int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
  461. int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
  462. int saa7164_api_initialize_dif(struct saa7164_port *port);
  463. int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
  464. int saa7164_api_set_encoder(struct saa7164_port *port);
  465. int saa7164_api_get_encoder(struct saa7164_port *port);
  466. int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
  467. int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
  468. int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
  469. int saa7164_api_set_videomux(struct saa7164_port *port);
  470. int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
  471. int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
  472. int saa7164_api_set_audio_std(struct saa7164_port *port);
  473. int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
  474. int saa7164_api_get_videomux(struct saa7164_port *port);
  475. int saa7164_api_set_vbi_format(struct saa7164_port *port);
  476. int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level);
  477. int saa7164_api_collect_debug(struct saa7164_dev *dev);
  478. int saa7164_api_get_load_info(struct saa7164_dev *dev,
  479. struct tmFwInfoStruct *i);
  480. /* ----------------------------------------------------------- */
  481. /* saa7164-cards.c */
  482. extern struct saa7164_board saa7164_boards[];
  483. extern const unsigned int saa7164_bcount;
  484. extern struct saa7164_subid saa7164_subids[];
  485. extern const unsigned int saa7164_idcount;
  486. extern void saa7164_card_list(struct saa7164_dev *dev);
  487. extern void saa7164_gpio_setup(struct saa7164_dev *dev);
  488. extern void saa7164_card_setup(struct saa7164_dev *dev);
  489. extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
  490. extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
  491. extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);
  492. /* ----------------------------------------------------------- */
  493. /* saa7164-dvb.c */
  494. extern int saa7164_dvb_register(struct saa7164_port *port);
  495. extern int saa7164_dvb_unregister(struct saa7164_port *port);
  496. /* ----------------------------------------------------------- */
  497. /* saa7164-buffer.c */
  498. extern struct saa7164_buffer *saa7164_buffer_alloc(
  499. struct saa7164_port *port, u32 len);
  500. extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
  501. extern void saa7164_buffer_display(struct saa7164_buffer *buf);
  502. extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
  503. extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
  504. extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
  505. struct saa7164_dev *dev, u32 len);
  506. extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
  507. extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);
  508. /* ----------------------------------------------------------- */
  509. /* saa7164-encoder.c */
  510. int saa7164_s_std(struct saa7164_port *port, v4l2_std_id id);
  511. int saa7164_g_std(struct saa7164_port *port, v4l2_std_id *id);
  512. int saa7164_enum_input(struct file *file, void *priv, struct v4l2_input *i);
  513. int saa7164_g_input(struct saa7164_port *port, unsigned int *i);
  514. int saa7164_s_input(struct saa7164_port *port, unsigned int i);
  515. int saa7164_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
  516. int saa7164_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
  517. int saa7164_g_frequency(struct saa7164_port *port, struct v4l2_frequency *f);
  518. int saa7164_s_frequency(struct saa7164_port *port,
  519. const struct v4l2_frequency *f);
  520. int saa7164_encoder_register(struct saa7164_port *port);
  521. void saa7164_encoder_unregister(struct saa7164_port *port);
  522. /* ----------------------------------------------------------- */
  523. /* saa7164-vbi.c */
  524. int saa7164_vbi_register(struct saa7164_port *port);
  525. void saa7164_vbi_unregister(struct saa7164_port *port);
  526. /* ----------------------------------------------------------- */
  527. extern unsigned int crc_checking;
  528. extern unsigned int saa_debug;
  529. #define dprintk(level, fmt, arg...)\
  530. do { if (saa_debug & level)\
  531. printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
  532. } while (0)
  533. #define log_warn(fmt, arg...)\
  534. do { \
  535. printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\
  536. } while (0)
  537. #define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2))
  538. #define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
  539. #define saa7164_readb(reg) readl(dev->bmmio + (reg))
  540. #define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg))