Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
saa7164.h
Go to the documentation of this file.
1 /*
2  * Driver for the NXP SAA7164 PCIe bridge
3  *
4  * Copyright (c) 2010 Steven Toth <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 /*
23  Driver architecture
24  *******************
25 
26  saa7164_core.c/buffer.c/cards.c/i2c.c/dvb.c
27  | : Standard Linux driver framework for creating
28  | : exposing and managing interfaces to the rest
29  | : of the kernel or userland. Also uses _fw.c to load
30  | : firmware direct into the PCIe bus, bypassing layers.
31  V
32  saa7164_api..() : Translate kernel specific functions/features
33  | : into command buffers.
34  V
35  saa7164_cmd..() : Manages the flow of command packets on/off,
36  | : the bus. Deal with bus errors, timeouts etc.
37  V
38  saa7164_bus..() : Manage a read/write memory ring buffer in the
39  | : PCIe Address space.
40  |
41  | saa7164_fw...() : Load any frimware
42  | | : direct into the device
43  V V
44  <- ----------------- PCIe address space -------------------- ->
45 */
46 
47 #include <linux/pci.h>
48 #include <linux/i2c.h>
49 #include <linux/kdev_t.h>
50 #include <linux/mutex.h>
51 #include <linux/crc32.h>
52 #include <linux/kthread.h>
53 #include <linux/freezer.h>
54 
55 #include <media/tuner.h>
56 #include <media/tveeprom.h>
57 #include <media/videobuf-dma-sg.h>
58 #include <media/videobuf-dvb.h>
59 #include <dvb_demux.h>
60 #include <dvb_frontend.h>
61 #include <dvb_net.h>
62 #include <dvbdev.h>
63 #include <dmxdev.h>
64 #include <media/v4l2-common.h>
65 #include <media/v4l2-ioctl.h>
66 #include <media/v4l2-chip-ident.h>
67 
68 #include "saa7164-reg.h"
69 #include "saa7164-types.h"
70 
71 #define SAA7164_MAXBOARDS 8
72 
73 #define UNSET (-1U)
74 #define SAA7164_BOARD_NOAUTO UNSET
75 #define SAA7164_BOARD_UNKNOWN 0
76 #define SAA7164_BOARD_UNKNOWN_REV2 1
77 #define SAA7164_BOARD_UNKNOWN_REV3 2
78 #define SAA7164_BOARD_HAUPPAUGE_HVR2250 3
79 #define SAA7164_BOARD_HAUPPAUGE_HVR2200 4
80 #define SAA7164_BOARD_HAUPPAUGE_HVR2200_2 5
81 #define SAA7164_BOARD_HAUPPAUGE_HVR2200_3 6
82 #define SAA7164_BOARD_HAUPPAUGE_HVR2250_2 7
83 #define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
84 #define SAA7164_BOARD_HAUPPAUGE_HVR2200_4 9
85 #define SAA7164_BOARD_HAUPPAUGE_HVR2200_5 10
86 
87 #define SAA7164_MAX_UNITS 8
88 #define SAA7164_TS_NUMBER_OF_LINES 312
89 #define SAA7164_PS_NUMBER_OF_LINES 256
90 #define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
91 #define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
92 #define SAA7164_MAX_VBI_BUFFERS 64
93 
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)
99 #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)
102 
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
111 #define DBGLVL_ENC 1024
112 #define DBGLVL_VBI 2048
113 #define DBGLVL_THR 4096
114 #define DBGLVL_CPU 8192
115 
116 #define SAA7164_NORMS \
117  (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443)
118 
119 enum port_t {
124 };
125 
130 };
131 
137 };
138 
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  */
157 struct saa7164_unit {
160  char *name;
164 };
165 
167  char *name;
168  enum port_t porta, portb, portc,
169  portd, porte, portf;
170  enum {
174  } chiprev;
176 };
177 
182 };
183 
187 };
188 
192 };
193 
198 };
199 
201  char name[32];
203 };
204 
206  struct list_head list;
207 
208  /* Attributes */
212 
214 };
215 
217 
218  /* RISC Core details */
225 
226  /* Firmware version */
232 };
233 
234 struct saa7164_dvb {
235  struct mutex lock;
238  struct dvb_demux demux;
239  struct dmxdev dmxdev;
242  struct dvb_net net;
243  int feeding;
244 };
245 
246 struct saa7164_i2c {
247  struct saa7164_dev *dev;
248 
250 
251  /* I2C I/O */
255 };
256 
257 struct saa7164_ctrl {
259 };
260 
262  char *name;
264 };
265 
271  u32 bitrate; /* bps */
272  u32 bitrate_peak; /* bps */
274  u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
275 
281 };
282 
288  u32 bitrate; /* bps */
289  u32 bitrate_peak; /* bps */
291  u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
292 
298 };
299 
300 struct saa7164_port;
301 
303  struct list_head list;
304 
305  /* Note of which h/w buffer list index position we occupy */
306  int idx;
307 
309 
310  /* Hardware Specific */
311  /* PCI Memory allocations */
312  enum saa7164_buffer_flags flags; /* Free, Busy, Full */
313 
314  /* A block of page align PCI memory */
315  u32 pci_size; /* PCI allocation size in bytes */
316  u64 __iomem *cpu; /* Virtual address */
317  dma_addr_t dma; /* Physical address */
318  u32 crc; /* Checksum for the entire buffer data */
319 
320  /* A page table that splits the block into a number of entries */
321  u32 pt_size; /* PCI allocation size in bytes */
322  u64 __iomem *pt_cpu; /* Virtual address */
323  dma_addr_t pt_dma; /* Physical address */
324 
325  /* Encoder fops */
328 };
329 
330 struct saa7164_port {
331 
332  struct saa7164_dev *dev;
333  enum port_t type;
334  int nr;
335 
336  /* --- Generic port attributes --- */
337 
338  /* HW stream parameters */
340 
341  /* DMA configuration values, is seeded during initialization */
343 
344  /* hardware specific registers */
352 
353  u32 numpte; /* Number of entries in array, only valid in head */
354 
357 
365 
371 
372  /* --- DVB Transport Specific --- */
373  struct saa7164_dvb dvb;
374 
375  /* --- Encoder/V4L related attributes --- */
376  /* Encoder */
377  /* Defaults established in saa7164-encoder.c */
395 
401 
403 
404  /* V4L Encoder Video */
408 
412 
413  /* V4L VBI */
416 
417  /* Debug */
424 };
425 
426 struct saa7164_dev {
429 
430  /* pci stuff */
431  struct pci_dev *pci;
432  unsigned char pci_rev, pci_lat;
439 
440  /* board details */
441  int nr;
444  char name[16];
445 
446  /* firmware status */
449 
453 
455 
456  /* Interrupt status and ack registers */
459 
461  struct mutex lock;
462 
463  /* I2c related */
464  struct saa7164_i2c i2c_bus[3];
465 
466  /* Transport related */
468 
469  /* Deferred command/api interrupts handling */
471 
472  /* A kernel thread to monitor the firmware log, used
473  * only in debug mode.
474  */
476 
477 };
478 
479 extern struct list_head saa7164_devlist;
480 extern unsigned int waitsecs;
481 extern unsigned int encoder_buffers;
482 extern unsigned int vbi_buffers;
483 
484 /* ----------------------------------------------------------- */
485 /* saa7164-core.c */
486 void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
490 
491 /* ----------------------------------------------------------- */
492 /* saa7164-fw.c */
494 
495 /* ----------------------------------------------------------- */
496 /* saa7164-i2c.c */
497 extern int saa7164_i2c_register(struct saa7164_i2c *bus);
498 extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);
499 extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
500  unsigned int cmd, void *arg);
501 
502 /* ----------------------------------------------------------- */
503 /* saa7164-bus.c */
504 int saa7164_bus_setup(struct saa7164_dev *dev);
505 void saa7164_bus_dump(struct saa7164_dev *dev);
506 int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
507  void *buf);
508 int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
509  void *buf, int peekonly);
510 
511 /* ----------------------------------------------------------- */
512 /* saa7164-cmd.c */
513 int saa7164_cmd_send(struct saa7164_dev *dev,
515  u16 size, void *buf);
516 void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
517 int saa7164_irq_dequeue(struct saa7164_dev *dev);
518 
519 /* ----------------------------------------------------------- */
520 /* saa7164-api.c */
523 int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
524  u32 datalen, u8 *data);
526  u32 datalen, u8 *data);
528  u32 datalen, u8 *data);
529 int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
541 int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
544 int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
550  struct tmFwInfoStruct *i);
551 
552 /* ----------------------------------------------------------- */
553 /* saa7164-cards.c */
554 extern struct saa7164_board saa7164_boards[];
555 extern const unsigned int saa7164_bcount;
556 
557 extern struct saa7164_subid saa7164_subids[];
558 extern const unsigned int saa7164_idcount;
559 
560 extern void saa7164_card_list(struct saa7164_dev *dev);
561 extern void saa7164_gpio_setup(struct saa7164_dev *dev);
562 extern void saa7164_card_setup(struct saa7164_dev *dev);
563 
564 extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
565 extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
566 extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);
567 
568 /* ----------------------------------------------------------- */
569 /* saa7164-dvb.c */
570 extern int saa7164_dvb_register(struct saa7164_port *port);
571 extern int saa7164_dvb_unregister(struct saa7164_port *port);
572 
573 /* ----------------------------------------------------------- */
574 /* saa7164-buffer.c */
575 extern struct saa7164_buffer *saa7164_buffer_alloc(
576  struct saa7164_port *port, u32 len);
577 extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
578 extern void saa7164_buffer_display(struct saa7164_buffer *buf);
579 extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
580 extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
582  struct saa7164_dev *dev, u32 len);
584 extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);
585 
586 /* ----------------------------------------------------------- */
587 /* saa7164-encoder.c */
590 
591 /* ----------------------------------------------------------- */
592 /* saa7164-vbi.c */
595 
596 /* ----------------------------------------------------------- */
597 
598 extern unsigned int crc_checking;
599 
600 extern unsigned int saa_debug;
601 #define dprintk(level, fmt, arg...)\
602  do { if (saa_debug & level)\
603  printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
604  } while (0)
605 
606 #define log_warn(fmt, arg...)\
607  do { \
608  printk(KERN_WARNING "%s: " fmt, dev->name, ## arg);\
609  } while (0)
610 
611 #define saa7164_readl(reg) readl(dev->lmmio + ((reg) >> 2))
612 #define saa7164_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
613 
614 #define saa7164_readb(reg) readl(dev->bmmio + (reg))
615 #define saa7164_writeb(reg, value) writel((value), dev->bmmio + (reg))
616