linux/drivers/staging/cx25821/cx25821.h
<<
>>
Prefs
   1/*
   2 *  Driver for the Conexant CX25821 PCIe bridge
   3 *
   4 *  Copyright (C) 2009 Conexant Systems Inc.
   5 *  Authors  <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
   6 *  Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
   7 *
   8 *  This program is free software; you can redistribute it and/or modify
   9 *  it under the terms of the GNU General Public License as published by
  10 *  the Free Software Foundation; either version 2 of the License, or
  11 *  (at your option) any later version.
  12 *
  13 *  This program is distributed in the hope that it will be useful,
  14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 *
  17 *  GNU General Public License for more details.
  18 *
  19 *  You should have received a copy of the GNU General Public License
  20 *  along with this program; if not, write to the Free Software
  21 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22 */
  23
  24#ifndef CX25821_H_
  25#define CX25821_H_
  26
  27#include <linux/pci.h>
  28#include <linux/i2c.h>
  29#include <linux/i2c-algo-bit.h>
  30#include <linux/interrupt.h>
  31#include <linux/delay.h>
  32#include <linux/sched.h>
  33#include <linux/kdev_t.h>
  34#include <linux/smp_lock.h>
  35
  36#include <media/v4l2-common.h>
  37#include <media/v4l2-device.h>
  38#include <media/tuner.h>
  39#include <media/tveeprom.h>
  40#include <media/videobuf-dma-sg.h>
  41#include <media/videobuf-dvb.h>
  42
  43#include "btcx-risc.h"
  44#include "cx25821-reg.h"
  45#include "cx25821-medusa-reg.h"
  46#include "cx25821-sram.h"
  47#include "cx25821-audio.h"
  48#include "media/cx2341x.h"
  49
  50#include <linux/version.h>
  51#include <linux/mutex.h>
  52
  53#define CX25821_VERSION_CODE KERNEL_VERSION(0, 0, 106)
  54
  55#define UNSET (-1U)
  56#define NO_SYNC_LINE (-1U)
  57
  58#define CX25821_MAXBOARDS 2
  59
  60#define TRUE    1
  61#define FALSE   0
  62#define LINE_SIZE_D1    1440
  63
  64/* Number of decoders and encoders */
  65#define MAX_DECODERS            8
  66#define MAX_ENCODERS            2
  67#define QUAD_DECODERS           4
  68#define MAX_CAMERAS             16
  69
  70/* Max number of inputs by card */
  71#define MAX_CX25821_INPUT 8
  72#define INPUT(nr) (&cx25821_boards[dev->board].input[nr])
  73#define RESOURCE_VIDEO0       1
  74#define RESOURCE_VIDEO1       2
  75#define RESOURCE_VIDEO2       4
  76#define RESOURCE_VIDEO3       8
  77#define RESOURCE_VIDEO4       16
  78#define RESOURCE_VIDEO5       32
  79#define RESOURCE_VIDEO6       64
  80#define RESOURCE_VIDEO7       128
  81#define RESOURCE_VIDEO8       256
  82#define RESOURCE_VIDEO9       512
  83#define RESOURCE_VIDEO10      1024
  84#define RESOURCE_VIDEO11      2048
  85#define RESOURCE_VIDEO_IOCTL  4096
  86
  87#define BUFFER_TIMEOUT     (HZ) /* 0.5 seconds */
  88
  89#define UNKNOWN_BOARD       0
  90#define CX25821_BOARD        1
  91
  92/* Currently supported by the driver */
  93#define CX25821_NORMS (\
  94        V4L2_STD_NTSC_M |  V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \
  95        V4L2_STD_PAL_BG |  V4L2_STD_PAL_DK    |  V4L2_STD_PAL_I    | \
  96        V4L2_STD_PAL_M  |  V4L2_STD_PAL_N     |  V4L2_STD_PAL_H    | \
  97        V4L2_STD_PAL_Nc)
  98
  99#define CX25821_BOARD_CONEXANT_ATHENA10 1
 100#define MAX_VID_CHANNEL_NUM     12
 101#define VID_CHANNEL_NUM 8
 102
 103struct cx25821_fmt {
 104        char *name;
 105        u32 fourcc;             /* v4l2 format id */
 106        int depth;
 107        int flags;
 108        u32 cxformat;
 109};
 110
 111struct cx25821_ctrl {
 112        struct v4l2_queryctrl v;
 113        u32 off;
 114        u32 reg;
 115        u32 mask;
 116        u32 shift;
 117};
 118
 119struct cx25821_tvnorm {
 120        char *name;
 121        v4l2_std_id id;
 122        u32 cxiformat;
 123        u32 cxoformat;
 124};
 125
 126struct cx25821_fh {
 127        struct cx25821_dev *dev;
 128        enum v4l2_buf_type type;
 129        int radio;
 130        u32 resources;
 131
 132        enum v4l2_priority prio;
 133
 134        /* video overlay */
 135        struct v4l2_window win;
 136        struct v4l2_clip *clips;
 137        unsigned int nclips;
 138
 139        /* video capture */
 140        struct cx25821_fmt *fmt;
 141        unsigned int width, height;
 142        int channel_id;
 143
 144        /* vbi capture */
 145        struct videobuf_queue vidq;
 146        struct videobuf_queue vbiq;
 147
 148        /* H264 Encoder specifics ONLY */
 149        struct videobuf_queue mpegq;
 150        atomic_t v4l_reading;
 151};
 152
 153enum cx25821_itype {
 154        CX25821_VMUX_COMPOSITE = 1,
 155        CX25821_VMUX_SVIDEO,
 156        CX25821_VMUX_DEBUG,
 157        CX25821_RADIO,
 158};
 159
 160enum cx25821_src_sel_type {
 161        CX25821_SRC_SEL_EXT_656_VIDEO = 0,
 162        CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
 163};
 164
 165/* buffer for one video frame */
 166struct cx25821_buffer {
 167        /* common v4l buffer stuff -- must be first */
 168        struct videobuf_buffer vb;
 169
 170        /* cx25821 specific */
 171        unsigned int bpl;
 172        struct btcx_riscmem risc;
 173        struct cx25821_fmt *fmt;
 174        u32 count;
 175};
 176
 177struct cx25821_input {
 178        enum cx25821_itype type;
 179        unsigned int vmux;
 180        u32 gpio0, gpio1, gpio2, gpio3;
 181};
 182
 183typedef enum {
 184        CX25821_UNDEFINED = 0,
 185        CX25821_RAW,
 186        CX25821_264
 187} port_t;
 188
 189struct cx25821_board {
 190        char *name;
 191        port_t porta, portb, portc;
 192        unsigned int tuner_type;
 193        unsigned int radio_type;
 194        unsigned char tuner_addr;
 195        unsigned char radio_addr;
 196
 197        u32 clk_freq;
 198        struct cx25821_input input[2];
 199};
 200
 201struct cx25821_subid {
 202        u16 subvendor;
 203        u16 subdevice;
 204        u32 card;
 205};
 206
 207struct cx25821_i2c {
 208        struct cx25821_dev *dev;
 209
 210        int nr;
 211
 212        /* i2c i/o */
 213        struct i2c_adapter i2c_adap;
 214        struct i2c_algo_bit_data i2c_algo;
 215        struct i2c_client i2c_client;
 216        u32 i2c_rc;
 217
 218        /* cx25821 registers used for raw addess */
 219        u32 i2c_period;
 220        u32 reg_ctrl;
 221        u32 reg_stat;
 222        u32 reg_addr;
 223        u32 reg_rdata;
 224        u32 reg_wdata;
 225};
 226
 227struct cx25821_dmaqueue {
 228        struct list_head active;
 229        struct list_head queued;
 230        struct timer_list timeout;
 231        struct btcx_riscmem stopper;
 232        u32 count;
 233};
 234
 235struct cx25821_data {
 236        struct cx25821_dev *dev;
 237        struct sram_channel *channel;
 238};
 239
 240struct cx25821_channel {
 241        struct v4l2_prio_state prio;
 242
 243        int ctl_bright;
 244        int ctl_contrast;
 245        int ctl_hue;
 246        int ctl_saturation;
 247        struct cx25821_data timeout_data;
 248
 249        struct video_device *video_dev;
 250        struct cx25821_dmaqueue vidq;
 251
 252        struct sram_channel *sram_channels;
 253
 254        struct mutex lock;
 255        int resources;
 256
 257        int pixel_formats;
 258        int use_cif_resolution;
 259        int cif_width;
 260};
 261
 262struct cx25821_dev {
 263        struct list_head devlist;
 264        atomic_t refcount;
 265        struct v4l2_device v4l2_dev;
 266
 267        /* pci stuff */
 268        struct pci_dev *pci;
 269        unsigned char pci_rev, pci_lat;
 270        int pci_bus, pci_slot;
 271        u32 base_io_addr;
 272        u32 __iomem *lmmio;
 273        u8 __iomem *bmmio;
 274        int pci_irqmask;
 275        int hwrevision;
 276
 277        u32 clk_freq;
 278
 279        /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
 280        struct cx25821_i2c i2c_bus[3];
 281
 282        int nr;
 283        struct mutex lock;
 284
 285        struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
 286
 287        /* board details */
 288        unsigned int board;
 289        char name[32];
 290
 291        /* Analog video */
 292        u32 resources;
 293        unsigned int input;
 294        u32 tvaudio;
 295        v4l2_std_id tvnorm;
 296        unsigned int tuner_type;
 297        unsigned char tuner_addr;
 298        unsigned int radio_type;
 299        unsigned char radio_addr;
 300        unsigned int has_radio;
 301        unsigned int videc_type;
 302        unsigned char videc_addr;
 303        unsigned short _max_num_decoders;
 304
 305        /* Analog Audio Upstream */
 306        int _audio_is_running;
 307        int _audiopixel_format;
 308        int _is_first_audio_frame;
 309        int _audiofile_status;
 310        int _audio_lines_count;
 311        int _audioframe_count;
 312        int _audio_upstream_channel_select;
 313        int _last_index_irq;    /* The last interrupt index processed. */
 314
 315        __le32 *_risc_audio_jmp_addr;
 316        __le32 *_risc_virt_start_addr;
 317        __le32 *_risc_virt_addr;
 318        dma_addr_t _risc_phys_addr;
 319        dma_addr_t _risc_phys_start_addr;
 320
 321        unsigned int _audiorisc_size;
 322        unsigned int _audiodata_buf_size;
 323        __le32 *_audiodata_buf_virt_addr;
 324        dma_addr_t _audiodata_buf_phys_addr;
 325        char *_audiofilename;
 326
 327        /* V4l */
 328        u32 freq;
 329        struct video_device *vbi_dev;
 330        struct video_device *radio_dev;
 331        struct video_device *ioctl_dev;
 332
 333        spinlock_t slock;
 334
 335        /* Video Upstream */
 336        int _line_size;
 337        int _prog_cnt;
 338        int _pixel_format;
 339        int _is_first_frame;
 340        int _is_running;
 341        int _file_status;
 342        int _lines_count;
 343        int _frame_count;
 344        int _channel_upstream_select;
 345        unsigned int _risc_size;
 346
 347        __le32 *_dma_virt_start_addr;
 348        __le32 *_dma_virt_addr;
 349        dma_addr_t _dma_phys_addr;
 350        dma_addr_t _dma_phys_start_addr;
 351
 352        unsigned int _data_buf_size;
 353        __le32 *_data_buf_virt_addr;
 354        dma_addr_t _data_buf_phys_addr;
 355        char *_filename;
 356        char *_defaultname;
 357
 358        int _line_size_ch2;
 359        int _prog_cnt_ch2;
 360        int _pixel_format_ch2;
 361        int _is_first_frame_ch2;
 362        int _is_running_ch2;
 363        int _file_status_ch2;
 364        int _lines_count_ch2;
 365        int _frame_count_ch2;
 366        int _channel2_upstream_select;
 367        unsigned int _risc_size_ch2;
 368
 369        __le32 *_dma_virt_start_addr_ch2;
 370        __le32 *_dma_virt_addr_ch2;
 371        dma_addr_t _dma_phys_addr_ch2;
 372        dma_addr_t _dma_phys_start_addr_ch2;
 373
 374        unsigned int _data_buf_size_ch2;
 375        __le32 *_data_buf_virt_addr_ch2;
 376        dma_addr_t _data_buf_phys_addr_ch2;
 377        char *_filename_ch2;
 378        char *_defaultname_ch2;
 379
 380        /* MPEG Encoder ONLY settings */
 381        u32 cx23417_mailbox;
 382        struct cx2341x_mpeg_params mpeg_params;
 383        struct video_device *v4l_device;
 384        atomic_t v4l_reader_count;
 385        struct cx25821_tvnorm encodernorm;
 386
 387        u32 upstream_riscbuf_size;
 388        u32 upstream_databuf_size;
 389        u32 upstream_riscbuf_size_ch2;
 390        u32 upstream_databuf_size_ch2;
 391        u32 audio_upstream_riscbuf_size;
 392        u32 audio_upstream_databuf_size;
 393        int _isNTSC;
 394        int _frame_index;
 395        int _audioframe_index;
 396        struct workqueue_struct *_irq_queues;
 397        struct work_struct _irq_work_entry;
 398        struct workqueue_struct *_irq_queues_ch2;
 399        struct work_struct _irq_work_entry_ch2;
 400        struct workqueue_struct *_irq_audio_queues;
 401        struct work_struct _audio_work_entry;
 402        char *input_filename;
 403        char *input_filename_ch2;
 404        int _frame_index_ch2;
 405        int _isNTSC_ch2;
 406        char *vid_stdname_ch2;
 407        int pixel_format_ch2;
 408        int channel_select_ch2;
 409        int command_ch2;
 410        char *input_audiofilename;
 411        char *vid_stdname;
 412        int pixel_format;
 413        int channel_select;
 414        int command;
 415        int channel_opened;
 416};
 417
 418struct upstream_user_struct {
 419        char *input_filename;
 420        char *vid_stdname;
 421        int pixel_format;
 422        int channel_select;
 423        int command;
 424};
 425
 426struct downstream_user_struct {
 427        char *vid_stdname;
 428        int pixel_format;
 429        int cif_resolution_enable;
 430        int cif_width;
 431        int decoder_select;
 432        int command;
 433        int reg_address;
 434        int reg_data;
 435};
 436
 437extern struct upstream_user_struct *up_data;
 438
 439static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
 440{
 441        return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
 442}
 443
 444#define cx25821_call_all(dev, o, f, args...) \
 445        v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
 446
 447extern struct list_head cx25821_devlist;
 448extern struct cx25821_board cx25821_boards[];
 449extern struct cx25821_subid cx25821_subids[];
 450
 451#define SRAM_CH00  0            /* Video A */
 452#define SRAM_CH01  1            /* Video B */
 453#define SRAM_CH02  2            /* Video C */
 454#define SRAM_CH03  3            /* Video D */
 455#define SRAM_CH04  4            /* Video E */
 456#define SRAM_CH05  5            /* Video F */
 457#define SRAM_CH06  6            /* Video G */
 458#define SRAM_CH07  7            /* Video H */
 459
 460#define SRAM_CH08  8            /* Audio A */
 461#define SRAM_CH09  9            /* Video Upstream I */
 462#define SRAM_CH10  10           /* Video Upstream J */
 463#define SRAM_CH11  11           /* Audio Upstream AUD_CHANNEL_B */
 464
 465#define VID_UPSTREAM_SRAM_CHANNEL_I     SRAM_CH09
 466#define VID_UPSTREAM_SRAM_CHANNEL_J     SRAM_CH10
 467#define AUDIO_UPSTREAM_SRAM_CHANNEL_B   SRAM_CH11
 468#define VIDEO_IOCTL_CH  11
 469
 470struct sram_channel {
 471        char *name;
 472        u32 i;
 473        u32 cmds_start;
 474        u32 ctrl_start;
 475        u32 cdt;
 476        u32 fifo_start;
 477        u32 fifo_size;
 478        u32 ptr1_reg;
 479        u32 ptr2_reg;
 480        u32 cnt1_reg;
 481        u32 cnt2_reg;
 482        u32 int_msk;
 483        u32 int_stat;
 484        u32 int_mstat;
 485        u32 dma_ctl;
 486        u32 gpcnt_ctl;
 487        u32 gpcnt;
 488        u32 aud_length;
 489        u32 aud_cfg;
 490        u32 fld_aud_fifo_en;
 491        u32 fld_aud_risc_en;
 492
 493        /* For Upstream Video */
 494        u32 vid_fmt_ctl;
 495        u32 vid_active_ctl1;
 496        u32 vid_active_ctl2;
 497        u32 vid_cdt_size;
 498
 499        u32 vip_ctl;
 500        u32 pix_frmt;
 501        u32 jumponly;
 502        u32 irq_bit;
 503};
 504extern struct sram_channel cx25821_sram_channels[];
 505
 506#define STATUS_SUCCESS         0
 507#define STATUS_UNSUCCESSFUL    -1
 508
 509#define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
 510#define cx_write(reg, value)     writel((value), dev->lmmio + ((reg)>>2))
 511
 512#define cx_andor(reg, mask, value) \
 513        writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
 514        ((value) & (mask)), dev->lmmio+((reg)>>2))
 515
 516#define cx_set(reg, bit)          cx_andor((reg), (bit), (bit))
 517#define cx_clear(reg, bit)        cx_andor((reg), (bit), 0)
 518
 519#define Set_GPIO_Bit(Bit)                       (1 << Bit)
 520#define Clear_GPIO_Bit(Bit)                     (~(1 << Bit))
 521
 522#define CX25821_ERR(fmt, args...)                       \
 523        pr_err("(%d): " fmt, dev->board, ##args)
 524#define CX25821_WARN(fmt, args...)                      \
 525        pr_warn("(%d): " fmt, dev->board, ##args)
 526#define CX25821_INFO(fmt, args...)                      \
 527        pr_info("(%d): " fmt, dev->board, ##args)
 528
 529extern int cx25821_i2c_register(struct cx25821_i2c *bus);
 530extern void cx25821_card_setup(struct cx25821_dev *dev);
 531extern int cx25821_ir_init(struct cx25821_dev *dev);
 532extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
 533extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
 534extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
 535extern void cx25821_gpio_init(struct cx25821_dev *dev);
 536extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
 537                                          int pin_number, int pin_logic_value);
 538
 539extern int medusa_video_init(struct cx25821_dev *dev);
 540extern int medusa_set_videostandard(struct cx25821_dev *dev);
 541extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
 542                                  int decoder_select);
 543extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
 544                                 int decoder);
 545extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
 546                               int decoder);
 547extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
 548extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
 549                                 int decoder);
 550
 551extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
 552                                      struct sram_channel *ch, unsigned int bpl,
 553                                      u32 risc);
 554
 555extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
 556                               struct scatterlist *sglist,
 557                               unsigned int top_offset,
 558                               unsigned int bottom_offset,
 559                               unsigned int bpl,
 560                               unsigned int padding, unsigned int lines);
 561extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
 562                                         struct btcx_riscmem *risc,
 563                                         struct scatterlist *sglist,
 564                                         unsigned int bpl,
 565                                         unsigned int lines, unsigned int lpi);
 566extern void cx25821_free_buffer(struct videobuf_queue *q,
 567                                struct cx25821_buffer *buf);
 568extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
 569                                u32 reg, u32 mask, u32 value);
 570extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
 571                                      struct sram_channel *ch);
 572extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
 573                                            struct sram_channel *ch);
 574
 575extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
 576extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
 577                                  int len, u32 bits, u32 mask);
 578extern void cx25821_dev_unregister(struct cx25821_dev *dev);
 579extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
 580                                            struct sram_channel *ch,
 581                                            unsigned int bpl, u32 risc);
 582
 583extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
 584                                        int channel_select, int pixel_format);
 585extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
 586                                        int channel_select, int pixel_format);
 587extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
 588                                       int channel_select);
 589extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
 590extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
 591extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
 592extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
 593                                             struct upstream_user_struct
 594                                             *up_data);
 595extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
 596                                             struct upstream_user_struct
 597                                             *up_data);
 598extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
 599                                         struct upstream_user_struct *up_data);
 600extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
 601extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
 602extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
 603extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
 604                                               struct sram_channel *ch,
 605                                               unsigned int bpl, u32 risc);
 606extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
 607                                     u32 format);
 608extern void cx25821_videoioctl_unregister(struct cx25821_dev *dev);
 609extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
 610                                              struct pci_dev *pci,
 611                                              struct video_device *template,
 612                                              char *type);
 613#endif
 614