linux/drivers/media/video/tlg2300/pd-common.h
<<
>>
Prefs
   1#ifndef PD_COMMON_H
   2#define PD_COMMON_H
   3
   4#include <linux/fs.h>
   5#include <linux/wait.h>
   6#include <linux/list.h>
   7#include <linux/videodev2.h>
   8#include <linux/semaphore.h>
   9#include <linux/usb.h>
  10#include <linux/poll.h>
  11#include <media/videobuf-vmalloc.h>
  12#include <media/v4l2-device.h>
  13
  14#include "dvb_frontend.h"
  15#include "dvbdev.h"
  16#include "dvb_demux.h"
  17#include "dmxdev.h"
  18
  19#define SBUF_NUM        8
  20#define MAX_BUFFER_NUM  6
  21#define PK_PER_URB      32
  22#define ISO_PKT_SIZE    3072
  23
  24#define POSEIDON_STATE_NONE             (0x0000)
  25#define POSEIDON_STATE_ANALOG           (0x0001)
  26#define POSEIDON_STATE_FM               (0x0002)
  27#define POSEIDON_STATE_DVBT             (0x0004)
  28#define POSEIDON_STATE_VBI              (0x0008)
  29#define POSEIDON_STATE_DISCONNECT       (0x0080)
  30
  31#define PM_SUSPEND_DELAY        3
  32
  33#define V4L_PAL_VBI_LINES       18
  34#define V4L_NTSC_VBI_LINES      12
  35#define V4L_PAL_VBI_FRAMESIZE   (V4L_PAL_VBI_LINES * 1440 * 2)
  36#define V4L_NTSC_VBI_FRAMESIZE  (V4L_NTSC_VBI_LINES * 1440 * 2)
  37
  38#define TUNER_FREQ_MIN          (45000000)
  39#define TUNER_FREQ_MAX          (862000000)
  40
  41struct vbi_data {
  42        struct video_device     *v_dev;
  43        struct video_data       *video;
  44        struct front_face       *front;
  45
  46        unsigned int            copied;
  47        unsigned int            vbi_size; /* the whole size of two fields */
  48        int                     users;
  49};
  50
  51/*
  52 * This is the running context of the video, it is useful for
  53 * resume()
  54 */
  55struct running_context {
  56        u32             freq;           /* VIDIOC_S_FREQUENCY */
  57        int             audio_idx;      /* VIDIOC_S_TUNER    */
  58        v4l2_std_id     tvnormid;       /* VIDIOC_S_STD     */
  59        int             sig_index;      /* VIDIOC_S_INPUT  */
  60        struct v4l2_pix_format pix;     /* VIDIOC_S_FMT   */
  61};
  62
  63struct video_data {
  64        /* v4l2 video device */
  65        struct video_device     *v_dev;
  66
  67        /* the working context */
  68        struct running_context  context;
  69
  70        /* for data copy */
  71        int             field_count;
  72
  73        char            *dst;
  74        int             lines_copied;
  75        int             prev_left;
  76
  77        int             lines_per_field;
  78        int             lines_size;
  79
  80        /* for communication */
  81        u8                      endpoint_addr;
  82        struct urb              *urb_array[SBUF_NUM];
  83        struct vbi_data         *vbi;
  84        struct poseidon         *pd;
  85        struct front_face       *front;
  86
  87        int                     is_streaming;
  88        int                     users;
  89
  90        /* for bubble handler */
  91        struct work_struct      bubble_work;
  92};
  93
  94enum pcm_stream_state {
  95        STREAM_OFF,
  96        STREAM_ON,
  97        STREAM_SUSPEND,
  98};
  99
 100#define AUDIO_BUFS (3)
 101#define CAPTURE_STREAM_EN 1
 102struct poseidon_audio {
 103        struct urb              *urb_array[AUDIO_BUFS];
 104        unsigned int            copied_position;
 105        struct snd_pcm_substream   *capture_pcm_substream;
 106
 107        unsigned int            rcv_position;
 108        struct  snd_card        *card;
 109        int                     card_close;
 110
 111        int                     users;
 112        int                     pm_state;
 113        enum pcm_stream_state   capture_stream;
 114};
 115
 116struct radio_data {
 117        __u32           fm_freq;
 118        int             users;
 119        unsigned int    is_radio_streaming;
 120        int             pre_emphasis;
 121        struct video_device *fm_dev;
 122};
 123
 124#define DVB_SBUF_NUM            4
 125#define DVB_URB_BUF_SIZE        0x2000
 126struct pd_dvb_adapter {
 127        struct dvb_adapter      dvb_adap;
 128        struct dvb_frontend     dvb_fe;
 129        struct dmxdev           dmxdev;
 130        struct dvb_demux        demux;
 131
 132        atomic_t                users;
 133        atomic_t                active_feed;
 134
 135        /* data transfer */
 136        s32                     is_streaming;
 137        struct urb              *urb_array[DVB_SBUF_NUM];
 138        struct poseidon         *pd_device;
 139        u8                      ep_addr;
 140        u8                      reserved[3];
 141
 142        /* data for power resume*/
 143        struct dvb_frontend_parameters fe_param;
 144
 145        /* for channel scanning */
 146        int             prev_freq;
 147        int             bandwidth;
 148        unsigned long   last_jiffies;
 149};
 150
 151struct front_face {
 152        /* use this field to distinguish VIDEO and VBI */
 153        enum v4l2_buf_type      type;
 154
 155        /* for host */
 156        struct videobuf_queue   q;
 157
 158        /* the bridge for host and device */
 159        struct videobuf_buffer  *curr_frame;
 160
 161        /* for device */
 162        spinlock_t              queue_lock;
 163        struct list_head        active;
 164        struct poseidon         *pd;
 165};
 166
 167struct poseidon {
 168        struct list_head        device_list;
 169
 170        struct mutex            lock;
 171        struct kref             kref;
 172
 173        /* for V4L2 */
 174        struct v4l2_device      v4l2_dev;
 175
 176        /* hardware info */
 177        struct usb_device       *udev;
 178        struct usb_interface    *interface;
 179        int                     cur_transfer_mode;
 180
 181        struct video_data       video_data;     /* video */
 182        struct vbi_data         vbi_data;       /* vbi   */
 183        struct poseidon_audio   audio;          /* audio (alsa) */
 184        struct radio_data       radio_data;     /* FM    */
 185        struct pd_dvb_adapter   dvb_data;       /* DVB   */
 186
 187        u32                     state;
 188        struct file             *file_for_stream; /* the active stream*/
 189
 190#ifdef CONFIG_PM
 191        int (*pm_suspend)(struct poseidon *);
 192        int (*pm_resume)(struct poseidon *);
 193        pm_message_t            msg;
 194
 195        struct work_struct      pm_work;
 196        u8                      portnum;
 197#endif
 198};
 199
 200struct poseidon_format {
 201        char    *name;
 202        int     fourcc;          /* video4linux 2         */
 203        int     depth;           /* bit/pixel             */
 204        int     flags;
 205};
 206
 207struct poseidon_tvnorm {
 208        v4l2_std_id     v4l2_id;
 209        char            name[12];
 210        u32             tlg_tvnorm;
 211};
 212
 213/* video */
 214int pd_video_init(struct poseidon *);
 215void pd_video_exit(struct poseidon *);
 216int stop_all_video_stream(struct poseidon *);
 217
 218/* alsa audio */
 219int poseidon_audio_init(struct poseidon *);
 220int poseidon_audio_free(struct poseidon *);
 221#ifdef CONFIG_PM
 222int pm_alsa_suspend(struct poseidon *);
 223int pm_alsa_resume(struct poseidon *);
 224#endif
 225
 226/* dvb */
 227int pd_dvb_usb_device_init(struct poseidon *);
 228void pd_dvb_usb_device_exit(struct poseidon *);
 229void pd_dvb_usb_device_cleanup(struct poseidon *);
 230int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
 231void dvb_stop_streaming(struct pd_dvb_adapter *);
 232
 233/* FM */
 234int poseidon_fm_init(struct poseidon *);
 235int poseidon_fm_exit(struct poseidon *);
 236struct video_device *vdev_init(struct poseidon *, struct video_device *);
 237
 238/* vendor command ops */
 239int send_set_req(struct poseidon*, u8, s32, s32*);
 240int send_get_req(struct poseidon*, u8, s32, void*, s32*, s32);
 241s32 set_tuner_mode(struct poseidon*, unsigned char);
 242
 243/* bulk urb alloc/free */
 244int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
 245                        struct usb_device *udev, u8 ep_addr,
 246                        int buf_size, gfp_t gfp_flags,
 247                        usb_complete_t complete_fn, void *context);
 248void free_all_urb_generic(struct urb **urb_array, int num);
 249
 250/* misc */
 251void poseidon_delete(struct kref *kref);
 252void destroy_video_device(struct video_device **v_dev);
 253extern int debug_mode;
 254void set_debug_mode(struct video_device *vfd, int debug_mode);
 255
 256#ifdef CONFIG_PM
 257#define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
 258#else
 259#define in_hibernation(pd) (0)
 260#endif
 261#define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
 262
 263#define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
 264                                __func__, __LINE__,  ## __VA_ARGS__)
 265
 266/* for power management */
 267#define logpm(pd) do {\
 268                        if (debug_mode & 0x10)\
 269                                log();\
 270                } while (0)
 271
 272#define logs(f) do { \
 273                        if ((debug_mode & 0x4) && \
 274                                (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
 275                                        log("type : VBI");\
 276                                                                \
 277                        if ((debug_mode & 0x8) && \
 278                                (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
 279                                        log("type : VIDEO");\
 280                } while (0)
 281#endif
 282
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.