1 /* 2 * em8300.h 3 * 4 * Copyright (C) 2000 Henrik Johansson <lhj@users.sourceforge.net> 5 * (C) 2000 Ze'ev Maor <zeev@users.sourceforge.net> 6 * (C) 2001 Rick Haines <rick@kuroyi.net> 7 * (C) 2001 Edward Salley <drawdeyellas@hotmail.com> 8 * (C) 2001 Jeremy T. Braun <jtbraun@mmit.edu> 9 * (C) 2001 Ralph Zimmermann <rz@ooe.net> 10 * (C) 2001 Daniel Chassot <Daniel.Chassot@vibro-meter.com> 11 * (C) 2002 Michael Hunold <michael@mihu.de> 12 * (C) 2002-2003 David Holm <mswitch@users.sourceforge.net> 13 * (C) 2003-2008 Nicolas Boullis <nboullis@debian.org> 14 * 15 * This program is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU General Public License 17 * as published by the Free Software Foundation; either version 2 18 * of the License, or (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU General Public License for more details. 24 * 25 * You should have received a copy of the GNU General Public License 26 * along with this program; if not, write to the Free Software 27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 */ 29 30 #ifndef LINUX_EM8300_H 31 #define LINUX_EM8300_H 32 33 typedef struct { 34 void *ucode; 35 int ucode_size; 36 } em8300_microcode_t; 37 38 typedef struct { 39 int reg; 40 int val; 41 int microcode_register; 42 } em8300_register_t; 43 44 typedef struct { 45 int brightness; 46 int contrast; 47 int saturation; 48 } em8300_bcs_t; 49 50 typedef struct { 51 int cal_mode; 52 int arg; 53 int arg2; 54 int result; 55 int result2; 56 } em8300_overlay_calibrate_t; 57 58 typedef struct { 59 int xpos, ypos; 60 int width, height; 61 } em8300_overlay_window_t; 62 63 typedef struct { 64 int xsize, ysize; 65 } em8300_overlay_screen_t; 66 67 typedef struct { 68 int attribute; 69 int value; 70 } em8300_attribute_t; 71 72 typedef struct { 73 int color; 74 int contrast; 75 int top; 76 int bottom; 77 int left; 78 int right; 79 } em8300_button_t; 80 81 #define MAX_UCODE_REGISTER 110 82 83 #define EM8300_IOCTL_INIT _IOW('C',0,em8300_microcode_t) 84 #define EM8300_IOCTL_READREG _IOWR('C',1,em8300_register_t) 85 #define EM8300_IOCTL_WRITEREG _IOW('C',2,em8300_register_t) 86 #define EM8300_IOCTL_GETSTATUS _IOR('C',3,char[1024]) 87 #define EM8300_IOCTL_SETBCS _IOW('C',4,em8300_bcs_t) 88 #define EM8300_IOCTL_GETBCS _IOR('C',4,em8300_bcs_t) 89 #define EM8300_IOCTL_SET_ASPECTRATIO _IOW('C',5,int) 90 #define EM8300_IOCTL_GET_ASPECTRATIO _IOR('C',5,int) 91 #define EM8300_IOCTL_SET_VIDEOMODE _IOW('C',6,int) 92 #define EM8300_IOCTL_GET_VIDEOMODE _IOR('C',6,int) 93 #define EM8300_IOCTL_SET_PLAYMODE _IOW('C',7,int) 94 #define EM8300_IOCTL_GET_PLAYMODE _IOR('C',7,int) 95 #define EM8300_IOCTL_SET_AUDIOMODE _IOW('C',8,int) 96 #define EM8300_IOCTL_GET_AUDIOMODE _IOR('C',8,int) 97 #define EM8300_IOCTL_SET_SPUMODE _IOW('C',9,int) 98 #define EM8300_IOCTL_GET_SPUMODE _IOR('C',9,int) 99 #define EM8300_IOCTL_OVERLAY_CALIBRATE _IOWR('C',10,em8300_overlay_calibrate_t) 100 #define EM8300_IOCTL_OVERLAY_SETMODE _IOW('C',11,int) 101 #define EM8300_IOCTL_OVERLAY_SETWINDOW _IOWR('C',12,em8300_overlay_window_t) 102 #define EM8300_IOCTL_OVERLAY_SETSCREEN _IOWR('C',13,em8300_overlay_screen_t) 103 #define EM8300_IOCTL_OVERLAY_GET_ATTRIBUTE _IOR('C',14,em8300_attribute_t) 104 #define EM8300_IOCTL_OVERLAY_SET_ATTRIBUTE _IOW('C',14,em8300_attribute_t) 105 #define EM8300_IOCTL_OVERLAY_SIGNALMODE _IOW('C',15,em8300_attribute_t) 106 #define EM8300_IOCTL_SCR_GET _IOR('C',16,unsigned) 107 #define EM8300_IOCTL_SCR_SET _IOW('C',16,unsigned) 108 #define EM8300_IOCTL_SCR_GETSPEED _IOR('C',17,unsigned) 109 #define EM8300_IOCTL_SCR_SETSPEED _IOW('C',17,unsigned) 110 #define EM8300_IOCTL_FLUSH _IOW('C',18,int) 111 #define EM8300_IOCTL_VBI _IOW('C',19,struct timeval) 112 113 #define EM8300_OVERLAY_SIGNAL_ONLY 1 114 #define EM8300_OVERLAY_SIGNAL_WITH_VGA 2 115 #define EM8300_OVERLAY_VGA_ONLY 3 116 117 #define EM8300_IOCTL_VIDEO_SETPTS _IOW('C',1,int) 118 #define EM8300_IOCTL_VIDEO_GETSCR _IOR('C',2,unsigned) 119 #define EM8300_IOCTL_VIDEO_SETSCR _IOW('C',2,unsigned) 120 121 #define EM8300_IOCTL_SPU_SETPTS _IOW('C',1,int) 122 #define EM8300_IOCTL_SPU_SETPALETTE _IOW('C',2,unsigned[16]) 123 #define EM8300_IOCTL_SPU_BUTTON _IOW('C',3,em8300_button_t) 124 125 #define EM8300_ASPECTRATIO_4_3 0 126 #define EM8300_ASPECTRATIO_16_9 1 127 #define EM8300_ASPECTRATIO_LAST 1 128 129 #define EM8300_VIDEOMODE_PAL 0 130 #define EM8300_VIDEOMODE_PAL60 1 131 #define EM8300_VIDEOMODE_NTSC 2 132 #define EM8300_VIDEOMODE_LAST 2 133 #ifndef EM8300_VIDEOMODE_DEFAULT 134 #define EM8300_VIDEOMODE_DEFAULT EM8300_VIDEOMODE_PAL 135 #endif 136 137 #define EM8300_AUDIOMODE_ANALOG 0 138 #define EM8300_AUDIOMODE_DIGITALPCM 1 139 #define EM8300_AUDIOMODE_DIGITALAC3 2 140 #ifndef EM8300_AUDIOMODE_DEFAULT 141 #define EM8300_AUDIOMODE_DEFAULT EM8300_AUDIOMODE_ANALOG 142 #endif 143 144 #define EM8300_SPUMODE_OFF 0 145 #define EM8300_SPUMODE_ON 1 146 147 #define EM8300_PLAYMODE_STOPPED 0 148 #define EM8300_PLAYMODE_PAUSED 1 149 #define EM8300_PLAYMODE_SLOWFORWARDS 2 150 #define EM8300_PLAYMODE_SLOWBACKWARDS 3 151 #define EM8300_PLAYMODE_SINGLESTEP 4 152 #define EM8300_PLAYMODE_PLAY 5 153 #define EM8300_PLAYMODE_REVERSEPLAY 6 154 #define EM8300_PLAYMODE_SCAN 7 155 #define EM8300_PLAYMODE_FRAMEBUF 8 156 157 #define EM8300_OVERLAY_MODE_OFF 0 158 #define EM8300_OVERLAY_MODE_RECTANGLE 1 159 #define EM8300_OVERLAY_MODE_OVERLAY 2 160 161 #define EM8300_OVERLAY_CALMODE_XOFFSET 1 162 #define EM8300_OVERLAY_CALMODE_YOFFSET 2 163 #define EM8300_OVERLAY_CALMODE_XCORRECTION 3 164 #define EM8300_OVERLAY_CALMODE_COLOR 4 165 166 #define EM9010_ATTRIBUTE_XCORR 1 167 #define EM9010_ATTRIBUTE_XOFFSET 2 168 #define EM9010_ATTRIBUTE_YOFFSET 3 169 #define EM9010_ATTRIBUTE_JITTER 4 170 #define EM9010_ATTRIBUTE_STABILITY 5 171 #define EM9010_ATTRIBUTE_KEYCOLOR_UPPER 6 172 #define EM9010_ATTRIBUTE_KEYCOLOR_LOWER 7 173 #define EM9010_ATTRIBUTE_MAX 7 174 175 #define EM8300_SUBDEVICE_CONTROL 0 176 #define EM8300_SUBDEVICE_VIDEO 1 177 #define EM8300_SUBDEVICE_AUDIO 2 178 #define EM8300_SUBDEVICE_SUBPICTURE 3 179 180 #ifndef PCI_VENDOR_ID_SIGMADESIGNS 181 #define PCI_VENDOR_ID_SIGMADESIGNS 0x1105 182 #define PCI_DEVICE_ID_SIGMADESIGNS_EM8300 0x8300 183 #endif 184 185 #define CLOCKGEN_SAMPFREQ_MASK 0xc0 186 #define CLOCKGEN_SAMPFREQ_66 0xc0 187 #define CLOCKGEN_SAMPFREQ_48 0x40 188 #define CLOCKGEN_SAMPFREQ_44 0x80 189 #define CLOCKGEN_SAMPFREQ_32 0x00 190 191 #define CLOCKGEN_OUTMASK 0x30 192 #define CLOCKGEN_DIGITALOUT 0x10 193 #define CLOCKGEN_ANALOGOUT 0x20 194 195 #define CLOCKGEN_MODEMASK 0x0f 196 #define CLOCKGEN_OVERLAYMODE_1 0x07 197 #define CLOCKGEN_TVMODE_1 0x0b 198 #define CLOCKGEN_OVERLAYMODE_2 0x04 199 #define CLOCKGEN_TVMODE_2 0x02 200 201 #define MVCOMMAND_STOP 0x0 202 #define MVCOMMAND_PAUSE 0x1 203 #define MVCOMMAND_START 0x3 204 #define MVCOMMAND_PLAYINTRA 0x4 205 #define MVCOMMAND_SYNC 0x6 206 #define MVCOMMAND_FLUSHBUF 0x10 207 #define MVCOMMAND_DISPLAYBUFINFO 0x11 208 209 #define MACOMMAND_STOP 0x0 210 #define MACOMMAND_PAUSE 0x1 211 #define MACOMMAND_PLAY 0x2 212 213 #define IRQSTATUS_VIDEO_VBL 0x10 214 #define IRQSTATUS_VIDEO_FIFO 0x2 215 #define IRQSTATUS_AUDIO_FIFO 0x8 216 217 #define ENCODER_UNKNOWN 0 218 #define ENCODER_ADV7175 1 219 #define ENCODER_ADV7170 2 220 #define ENCODER_BT865 3 221 222 #ifdef __KERNEL__ 223 224 #define EM8300_MAX 4 225 226 #define EM8300_MAJOR 121 227 #define EM8300_LOGNAME "em8300" 228 extern int major; 229 230 #include <linux/version.h> 231 #include <linux/types.h> /* ulong, uint32_t */ 232 #include <linux/i2c.h> /* struct i2c_adapter */ 233 #include <linux/i2c-algo-bit.h> /* struct i2c_algo_bit_data */ 234 #include <linux/time.h> /* struct timeval */ 235 #include <linux/wait.h> /* wait_queue_head_t */ 236 #include <linux/list.h> /* struct list_head */ 237 238 #if defined(CONFIG_SND) || defined(CONFIG_SND_MODULE) 239 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) 240 #define snd_card_t struct snd_card 241 #else 242 #include <sound/driver.h> 243 #include <sound/core.h> 244 #include <sound/pcm.h> 245 #endif 246 #endif 247 248 struct dicom_s { 249 int luma; 250 int chroma; 251 int frametop; 252 int framebottom; 253 int frameleft; 254 int frameright; 255 int visibletop; 256 int visiblebottom; 257 int visibleleft; 258 int visibleright; 259 int tvout; 260 }; 261 262 struct displaybuffer_info_s { 263 int xsize; 264 int ysize; 265 int xsize2; 266 int flag1,flag2; 267 int buffer1; 268 int buffer2; 269 int unk_present; 270 int unknown1; 271 int unknown2; 272 int unknown3; 273 }; 274 275 struct em8300_audio_s { 276 int channels; 277 int format; 278 int speed; 279 int slotsize; 280 int enable_bits; 281 }; 282 283 struct em8300_model_config_s { 284 int use_bt865; 285 int dicom_other_pal; 286 int dicom_fix; 287 int dicom_control; 288 int bt865_ucode_timeout; 289 int activate_loopback; 290 }; 291 292 struct adv717x_model_config_s { 293 int pixelport_16bit; 294 int pixelport_other_pal; 295 int pixeldata_adjust_ntsc; 296 int pixeldata_adjust_pal; 297 }; 298 299 struct bt865_model_config_s { 300 }; 301 302 struct em8300_config_s { 303 struct em8300_model_config_s model; 304 struct adv717x_model_config_s adv717x_model; 305 struct bt865_model_config_s bt865_model; 306 }; 307 308 struct em8300_s 309 { 310 char name[40]; 311 312 int chip_revision; 313 int pci_revision; 314 315 int inuse[4]; 316 int nonblock[4]; 317 int ucodeloaded; 318 319 struct pci_dev *dev; 320 ulong adr; 321 volatile unsigned *mem; 322 ulong memsize; 323 324 int playmode; 325 326 #if defined(CONFIG_SND) || defined(CONFIG_SND_MODULE) 327 snd_card_t *alsa_card; 328 #endif 329 330 /* Fifos */ 331 struct fifo_s *mvfifo; 332 struct fifo_s *mafifo; 333 struct fifo_s *spfifo; 334 int mtrr_reg; 335 336 /* DICOM */ 337 int dicom_vertoffset; 338 int dicom_horizoffset; 339 int dicom_brightness; 340 int dicom_contrast; 341 int dicom_saturation; 342 int dicom_tvout; 343 struct displaybuffer_info_s dbuf_info; 344 345 /* I2C */ 346 int i2c_pin_reg; 347 int i2c_oe_reg; 348 349 /* different between revision 1 and revision 2 boards */ 350 int mystery_divisor; 351 352 /* I2C bus 1*/ 353 struct i2c_algo_bit_data i2c_data_1; 354 struct i2c_adapter i2c_ops_1; 355 356 /* I2C bus 2*/ 357 struct i2c_algo_bit_data i2c_data_2; 358 struct i2c_adapter i2c_ops_2; 359 360 /* I2C clients */ 361 int encoder_type; 362 struct i2c_client *encoder; 363 struct i2c_client *eeprom; 364 365 /* Microcode registers */ 366 unsigned ucode_regs[MAX_UCODE_REGISTER]; 367 int var_ucode_reg1; /* These are registers that differ */ 368 int var_ucode_reg2; /* between versions 1 and 2 of the board */ 369 int var_ucode_reg3; /* " */ 370 371 /* Interrupt */ 372 unsigned irqmask; 373 374 /* Clockgenerator */ 375 int clockgen; 376 int clockgen_overlaymode; 377 int clockgen_tvmode; 378 379 /* Timing measurement */ 380 struct timeval tv, last_status_time; 381 long irqtimediff; 382 int irqcount; 383 int frames; 384 int scr; 385 386 /* Audio */ 387 struct em8300_audio_s audio; 388 int audio_mode; 389 int pcm_mode; 390 int dsp_num; 391 /* Channel status for S/PDIF */ 392 unsigned int channel_status_pos; 393 unsigned char channel_status[24]; 394 enum { NONE, OSS, ALSA } audio_driver_style; 395 struct semaphore audio_driver_style_lock; 396 397 /* Video */ 398 int video_mode; 399 int video_playmode; 400 int aspect_ratio; 401 int zoom; 402 uint32_t video_pts; 403 uint32_t video_lastpts; 404 int video_ptsvalid,video_offset,video_count; 405 int video_ptsfifo_ptr; 406 #if LINUX_VERSION_CODE < 0x020314 407 struct wait_queue *video_ptsfifo_wait; 408 struct wait_queue *vbi_wait; 409 #else 410 wait_queue_head_t video_ptsfifo_wait; 411 wait_queue_head_t vbi_wait; 412 #endif 413 int video_ptsfifo_waiting; 414 int video_first; 415 int var_video_value; 416 417 /* Sub Picture */ 418 int sp_pts, sp_ptsvalid, sp_count; 419 int sp_ptsfifo_ptr; 420 #if LINUX_VERSION_CODE < 0x020314 421 struct wait_queue *sp_ptsfifo_wait; 422 #else 423 wait_queue_head_t sp_ptsfifo_wait; 424 #endif 425 int sp_ptsfifo_waiting; 426 int sp_mode; 427 428 int linecounter; 429 430 /* EM9010 overlay processor */ 431 int overlay_enabled; 432 int overlay_mode; 433 int overlay_gamma_enable; 434 int overlay_xres; 435 int overlay_yres; 436 int overlay_frame_xpos; 437 int overlay_frame_ypos; 438 int overlay_frame_width; 439 int overlay_frame_height; 440 int overlay_a[EM9010_ATTRIBUTE_MAX+1]; 441 int overlay_double_y; 442 int overlay_xcorr_default; 443 int overlay_70; 444 int overlay_dword_24bb8; 445 446 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0) 447 /* Memory exported via mmap() */ 448 struct list_head memory; 449 #endif 450 451 /* Checksum for the on-board eeprom */ 452 u8 *eeprom_checksum; 453 454 int model; 455 456 struct em8300_config_s config; 457 458 /* To support different options for different cards */ 459 unsigned int card_nr; 460 }; 461 462 #if defined(CONFIG_SND) || defined(CONFIG_SND_MODULE) 463 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) 464 #undef snd_card_t 465 #endif 466 #endif 467 468 #define TIMEDIFF(a,b) a.tv_usec - b.tv_usec + \ 469 1000000 * (a.tv_sec - b.tv_sec) 470 471 472 /* 473 Prototypes 474 */ 475 476 /* em8300_i2c.c */ 477 int em8300_i2c_init1(struct em8300_s *em); 478 int em8300_i2c_init2(struct em8300_s *em); 479 void em8300_i2c_exit(struct em8300_s *em); 480 void em8300_clockgen_write(struct em8300_s *em, int abyte); 481 482 void em9010_write(struct em8300_s *em, int reg, int data); 483 int em9010_read(struct em8300_s *em, int reg); 484 int em9010_read16(struct em8300_s *em, int reg); 485 void em9010_write16(struct em8300_s *em, int reg, int value); 486 487 /* em8300_audio.c */ 488 int em8300_audio_ioctl(struct em8300_s *em,unsigned int cmd, unsigned long arg); 489 int em8300_audio_flush(struct em8300_s *em); 490 int em8300_audio_open(struct em8300_s *em); 491 int em8300_audio_release(struct em8300_s *em); 492 int em8300_audio_setup(struct em8300_s *em); 493 ssize_t em8300_audio_write(struct em8300_s *em, const char * buf, 494 size_t count, loff_t *ppos); 495 int mpegaudio_command(struct em8300_s *em, int cmd); 496 497 /* em8300_ucode.c */ 498 void em8300_ucode_upload(struct em8300_s *em, void *ucode, int ucode_size); 499 void em8300_require_ucode(struct em8300_s *em); 500 501 /* em8300_misc.c */ 502 int em8300_setregblock(struct em8300_s *em, int offset, int val, int len); 503 int em8300_writeregblock(struct em8300_s *em, int offset, unsigned *buf, int len); 504 int em8300_waitfor(struct em8300_s *em, int reg, int val, int mask); 505 int em8300_waitfor_not(struct em8300_s *em, int reg, int val, int mask); 506 507 /* em8300_dicom.c */ 508 void em8300_dicom_setBCS(struct em8300_s *em, int brightness, int contrast, int saturation); 509 void em8300_dicom_enable(struct em8300_s *em); 510 void em8300_dicom_disable(struct em8300_s *em); 511 int em8300_dicom_update(struct em8300_s *em); 512 void em8300_dicom_init(struct em8300_s *em); 513 int em8300_dicom_get_dbufinfo(struct em8300_s *em); 514 void em8300_dicom_fill_dispbuffers(struct em8300_s *em, int xpos, int ypos, int xsize, 515 int ysize, unsigned int pat1, unsigned int pat2); 516 517 /* em8300_video.c */ 518 void em8300_video_open(struct em8300_s *em); 519 int em8300_video_setplaymode(struct em8300_s *em, int mode); 520 int em8300_video_sync(struct em8300_s *em); 521 int em8300_video_flush(struct em8300_s *em); 522 int em8300_video_setup(struct em8300_s *em); 523 int em8300_video_release(struct em8300_s *em); 524 void em8300_video_setspeed(struct em8300_s *em, int speed); 525 ssize_t em8300_video_write(struct em8300_s *em, const char * buf, 526 size_t count, loff_t *ppos); 527 int em8300_video_ioctl(struct em8300_s *em, unsigned int cmd, unsigned long arg); 528 void em8300_video_check_ptsfifo(struct em8300_s *em); 529 530 /* em8300_spu.c */ 531 ssize_t em8300_spu_write(struct em8300_s *em, const char * buf, 532 size_t count, loff_t *ppos); 533 int em8300_spu_open(struct em8300_s *em); 534 int em8300_spu_ioctl(struct em8300_s *em, unsigned int cmd, unsigned long arg); 535 int em8300_spu_init(struct em8300_s *em); 536 void em8300_spu_check_ptsfifo(struct em8300_s *em); 537 int em8300_ioctl_setspumode(struct em8300_s *em, int mode); 538 void em8300_spu_release(struct em8300_s *em); 539 540 /* em8300_ioctl.c */ 541 int em8300_control_ioctl(struct em8300_s *em, int cmd, unsigned long arg); 542 int em8300_ioctl_setvideomode(struct em8300_s *em, int mode); 543 int em8300_ioctl_setaspectratio(struct em8300_s *em, int ratio); 544 int em8300_ioctl_getstatus(struct em8300_s *em, char *usermsg); 545 int em8300_ioctl_init(struct em8300_s *em, em8300_microcode_t *useruc); 546 void em8300_ioctl_enable_videoout(struct em8300_s *em, int mode); 547 int em8300_ioctl_setplaymode(struct em8300_s *em, int mode); 548 int em8300_ioctl_setaudiomode(struct em8300_s *em, int mode); 549 int em8300_ioctl_getaudiomode(struct em8300_s *em, long int mode); 550 int em8300_ioctl_overlay_calibrate(struct em8300_s *em, em8300_overlay_calibrate_t *c); 551 int em8300_ioctl_overlay_setwindow(struct em8300_s *em,em8300_overlay_window_t *w); 552 int em8300_ioctl_overlay_setscreen(struct em8300_s *em,em8300_overlay_screen_t *s); 553 int em8300_ioctl_overlay_setmode(struct em8300_s *em,int val); 554 555 /* em9010.c */ 556 int em9010_cabledetect(struct em8300_s *em); 557 int em9010_calibrate_xoffset(struct em8300_s *em); 558 int em9010_calibrate_yoffset(struct em8300_s *em); 559 int em9010_init(struct em8300_s *em); 560 int em9010_overlay_set_signalmode(struct em8300_s *em, int val); 561 int em9010_overlay_update(struct em8300_s *em); 562 int em9010_overlay_set_res(struct em8300_s *em, int xres, int yres); 563 void sub_4288c(struct em8300_s *em, int pa, int pb, int pc, int pd, int pe, int pf, 564 int pg, int ph); 565 int em9010_get_attribute(struct em8300_s *em, int attribute); 566 int em9010_set_attribute(struct em8300_s *em, int attribute, int value); 567 568 #endif /* __KERNEL__ */ 569 570 #endif /* LINUX_EM8300_H */ 571