V4L/DVB: cx18, cx23885, v4l2 doc, MAINTAINERS: Update Andy Walls' email address
[safe/jmp/linux-2.6] / drivers / media / video / cx18 / cx18-driver.h
index c6a1e90..9bc51a9 100644 (file)
@@ -4,7 +4,7 @@
  *  Derived from ivtv-driver.h
  *
  *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
- *  Copyright (C) 2008  Andy Walls <awalls@radix.net>
+ *  Copyright (C) 2008  Andy Walls <awalls@md.metrocast.net>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -42,6 +42,7 @@
 #include <linux/pagemap.h>
 #include <linux/workqueue.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 #include <asm/byteorder.h>
 
 #include <linux/dvb/video.h>
@@ -50,6 +51,7 @@
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-device.h>
 #include <media/tuner.h>
+#include <media/ir-kbd-i2c.h>
 #include "cx18-mailbox.h"
 #include "cx18-av-core.h"
 #include "cx23418.h"
 /* Maximum firmware DMA buffers per stream */
 #define CX18_MAX_FW_MDLS_PER_STREAM 63
 
+/* YUV buffer sizes in bytes to ensure integer # of frames per buffer */
+#define CX18_UNIT_ENC_YUV_BUFSIZE      (720 *  32 * 3 / 2) /* bytes */
+#define CX18_625_LINE_ENC_YUV_BUFSIZE  (CX18_UNIT_ENC_YUV_BUFSIZE * 576/32)
+#define CX18_525_LINE_ENC_YUV_BUFSIZE  (CX18_UNIT_ENC_YUV_BUFSIZE * 480/32)
+
+/* IDX buffer size should be a multiple of the index entry size from the chip */
+struct cx18_enc_idx_entry {
+       __le32 length;
+       __le32 offset_low;
+       __le32 offset_high;
+       __le32 flags;
+       __le32 pts_low;
+       __le32 pts_high;
+} __attribute__ ((packed));
+#define CX18_UNIT_ENC_IDX_BUFSIZE \
+       (sizeof(struct cx18_enc_idx_entry) * V4L2_ENC_IDX_ENTRIES)
+
 /* DMA buffer, default size in kB allocated */
 #define CX18_DEFAULT_ENC_TS_BUFSIZE   32
 #define CX18_DEFAULT_ENC_MPG_BUFSIZE  32
-#define CX18_DEFAULT_ENC_IDX_BUFSIZE  32
-#define CX18_DEFAULT_ENC_YUV_BUFSIZE 128
-/* Default VBI bufsize based on standards supported by card tuner for now */
+#define CX18_DEFAULT_ENC_IDX_BUFSIZE  (CX18_UNIT_ENC_IDX_BUFSIZE * 1 / 1024 + 1)
+#define CX18_DEFAULT_ENC_YUV_BUFSIZE  (CX18_UNIT_ENC_YUV_BUFSIZE * 3 / 1024 + 1)
 #define CX18_DEFAULT_ENC_PCM_BUFSIZE   4
 
 /* i2c stuff */
 #define CX18_WARN_DEV(dev, fmt, args...)     v4l2_warn(dev, fmt , ## args)
 #define CX18_INFO_DEV(dev, fmt, args...)     v4l2_info(dev, fmt , ## args)
 
-/* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
-#define MPEG_FRAME_TYPE_IFRAME 1
-#define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
-#define MPEG_FRAME_TYPE_ALL 7
-
-#define CX18_MAX_PGM_INDEX (400)
-
 extern int cx18_debug;
 
-
 struct cx18_options {
        int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */
        int cardtype;           /* force card type on load */
@@ -246,8 +256,8 @@ struct cx18_options {
        int radio;              /* enable/disable radio */
 };
 
-/* per-buffer bit flags */
-#define CX18_F_B_NEED_BUF_SWAP  0      /* this buffer should be byte swapped */
+/* per-mdl bit flags */
+#define CX18_F_M_NEED_SWAP  0  /* mdl buffer data must be endianess swapped */
 
 /* per-stream, s_flags */
 #define CX18_F_S_CLAIMED       3       /* this stream is claimed */
@@ -271,21 +281,44 @@ struct cx18_options {
 #define CX18_SLICED_TYPE_WSS_625        (5)
 #define CX18_SLICED_TYPE_VPS            (7)
 
+/**
+ * list_entry_is_past_end - check if a previous loop cursor is off list end
+ * @pos:       the type * previously used as a loop cursor.
+ * @head:      the head for your list.
+ * @member:    the name of the list_struct within the struct.
+ *
+ * Check if the entry's list_head is the head of the list, thus it's not a
+ * real entry but was the loop cursor that walked past the end
+ */
+#define list_entry_is_past_end(pos, head, member) \
+       (&pos->member == (head))
+
 struct cx18_buffer {
        struct list_head list;
        dma_addr_t dma_handle;
-       u32 id;
-       unsigned long b_flags;
-       unsigned skipped;
        char *buf;
 
        u32 bytesused;
        u32 readpos;
 };
 
+struct cx18_mdl {
+       struct list_head list;
+       u32 id;         /* index into cx->scb->cpu_mdl[] of 1st cx18_mdl_ent */
+
+       unsigned int skipped;
+       unsigned long m_flags;
+
+       struct list_head buf_list;
+       struct cx18_buffer *curr_buf; /* current buffer in list for reading */
+
+       u32 bytesused;
+       u32 readpos;
+};
+
 struct cx18_queue {
        struct list_head list;
-       atomic_t buffers;
+       atomic_t depth;
        u32 bytesused;
        spinlock_t lock;
 };
@@ -337,7 +370,7 @@ struct cx18_stream {
        const char *name;               /* name of the stream */
        int type;                       /* stream type */
        u32 handle;                     /* task handle */
-       unsigned mdl_offset;
+       unsigned int mdl_base_idx;
 
        u32 id;
        unsigned long s_flags;  /* status flags, see above */
@@ -346,14 +379,20 @@ struct cx18_stream {
                                   PCI_DMA_NONE */
        wait_queue_head_t waitq;
 
-       /* Buffer Stats */
-       u32 buffers;
-       u32 buf_size;
+       /* Buffers */
+       struct list_head buf_pool;      /* buffers not attached to an MDL */
+       u32 buffers;                    /* total buffers owned by this stream */
+       u32 buf_size;                   /* size in bytes of a single buffer */
+
+       /* MDL sizes - all stream MDLs are the same size */
+       u32 bufs_per_mdl;
+       u32 mdl_size;           /* total bytes in all buffers in a mdl */
 
-       /* Buffer Queues */
-       struct cx18_queue q_free;       /* free buffers */
-       struct cx18_queue q_busy;       /* busy buffers - in use by firmware */
-       struct cx18_queue q_full;       /* full buffers - data for user apps */
+       /* MDL Queues */
+       struct cx18_queue q_free;       /* free - in rotation, not committed */
+       struct cx18_queue q_busy;       /* busy - in use by firmware */
+       struct cx18_queue q_full;       /* full - data for user apps */
+       struct cx18_queue q_idle;       /* idle - not in rotation */
 
        struct work_struct out_work_order;
 
@@ -481,10 +520,11 @@ struct vbi_info {
        u32 inserted_frame;
 
        /*
-        * A dummy driver stream transfer buffer with a copy of the next
+        * A dummy driver stream transfer mdl & buffer with a copy of the next
         * sliced_mpeg_data[] buffer for output to userland apps.
         * Only used in cx18-fileops.c, but its state needs to persist at times.
         */
+       struct cx18_mdl sliced_mpeg_mdl;
        struct cx18_buffer sliced_mpeg_buf;
 };
 
@@ -511,10 +551,9 @@ struct cx18 {
        u8 is_60hz;
        u8 nof_inputs;          /* number of video inputs */
        u8 nof_audio_inputs;    /* number of audio inputs */
-       u16 buffer_id;          /* buffer ID counter */
        u32 v4l2_cap;           /* V4L2 capabilities of card */
        u32 hw_flags;           /* Hardware description of the board */
-       unsigned mdl_offset;
+       unsigned int free_mdl_idx;
        struct cx18_scb __iomem *scb; /* pointer to SCB */
        struct mutex epu2apu_mb_lock; /* protect driver to chip mailbox in SCB*/
        struct mutex epu2cpu_mb_lock; /* protect driver to chip mailbox in SCB*/
@@ -536,6 +575,10 @@ struct cx18 {
        int stream_buffers[CX18_MAX_STREAMS]; /* # of buffers for each stream */
        int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */
        struct cx18_stream streams[CX18_MAX_STREAMS];   /* Stream data */
+       struct snd_cx18_card *alsa; /* ALSA interface for PCM capture stream */
+       void (*pcm_announce_callback)(struct snd_cx18_card *card, u8 *pcm_data,
+                                     size_t num_bytes);
+
        unsigned long i_flags;  /* global cx18 flags */
        atomic_t ana_capturing; /* count number of active analog capture streams */
        atomic_t tot_capturing; /* total count number of active capture streams */
@@ -553,12 +596,6 @@ struct cx18 {
 
        struct vbi_info vbi;
 
-       u32 pgm_info_offset;
-       u32 pgm_info_num;
-       u32 pgm_info_write_idx;
-       u32 pgm_info_read_idx;
-       struct v4l2_enc_idx_entry pgm_info[CX18_MAX_PGM_INDEX];
-
        u64 mpg_data_received;
        u64 vbi_data_inserted;
 
@@ -585,6 +622,8 @@ struct cx18 {
        struct i2c_algo_bit_data i2c_algo[2];
        struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2];
 
+       struct IR_i2c_init_data ir_i2c_init_data;
+
        /* gpio */
        u32 gpio_dir;
        u32 gpio_val;
@@ -599,6 +638,9 @@ struct cx18 {
        u32 active_input;
        v4l2_std_id std;
        v4l2_std_id tuner_std;  /* The norm of the tuner (fixed) */
+
+       /* Used for cx18-alsa module loading */
+       struct work_struct request_module_wk;
 };
 
 static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev)
@@ -606,6 +648,9 @@ static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev)
        return container_of(v4l2_dev, struct cx18, v4l2_dev);
 }
 
+/* cx18 extensions to be loaded */
+extern int (*cx18_ext_init)(struct cx18 *);
+
 /* Globals */
 extern int cx18_first_minor;