whitespace cosmetics: Remove all trailing whitespace.
[mplayer.git] / vidix / cyberblade_vid.c
index 3da2f4d..f46095a 100644 (file)
@@ -1,40 +1,35 @@
 /*
-    Driver for CyberBlade/i1 - Version 0.1.4
-
-    Copyright (C) 2002 by Alastair M. Robinson.
-    Official homepage: http://www.blackfiveservices.co.uk/EPIAVidix.shtml
-
-    Based on Permedia 3 driver by Måns Rullgård
-
-    Thanks to Gilles Frattini for bugfixes
-
-    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
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-    Changes:
-    18/01/03
-      MMIO is no longer used, sidestepping cache issues on EPIA-800
-      TV-Out modes are now better supported - this should be the end
-        of the magenta stripes :)
-      Brightness/Contrast controls disabled for the time being - they were
-        seriously degrading picture quality, especially with TV-Out.
-
-    To Do:
-    Implement Hue/Saturation controls
-    Support / Test multiple frames
-    Test colour-key code more extensively
-*/
+ * VIDIX driver for VIA Cyberblade/i1 chipsets.
+ * Brightness/Contrast controls disabled for the time being - they were
+ * seriously degrading picture quality, especially with TV-Out.
+ *
+ * Copyright (C) 2002 Alastair M. Robinson
+ * http://www.blackfiveservices.co.uk/EPIAVidix.shtml
+ * based on Permedia 3 driver by Måns Rullgård
+ * thanks to Gilles Frattini for bugfixes
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* To Do:
+ *   Implement Hue/Saturation controls
+ *   Support / Test multiple frames
+ *   Test colour-key code more extensively
+ */
 
 #include <errno.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <unistd.h>
 
+#include "config.h"
 #include "vidix.h"
 #include "fourcc.h"
-#include "../libdha/libdha.h"
-#include "../libdha/pci_ids.h"
-#include "../libdha/pci_names.h"
-#include "../config.h"
+#include "dha.h"
+#include "pci_ids.h"
+#include "pci_names.h"
 
 #include "cyberblade_regs.h"
 
-pciinfo_t pci_info;
+static pciinfo_t pci_info;
 
-char save_colourkey[6];
-char *cyberblade_mem;
+static char save_colourkey[6];
+static char *cyberblade_mem;
 
 #ifdef DEBUG_LOGFILE
-FILE *logfile=0;
+static FILE *logfile=0;
 #define LOGWRITE(x) {if(logfile) fprintf(logfile,x);}
 #else
 #define LOGWRITE(x)
 #endif
 
-/* Helper functions for reading registers. */    
-
-static int CRINW(int reg)
-{
-       int result;
-       result=CRINB(reg);
-       result|=CRINB(reg+1)<<8;
-       return(result);
-}
+/* Helper functions for reading registers. */
 
 static void CROUTW(int reg,int val)
 {
@@ -80,43 +67,12 @@ static void CROUTW(int reg,int val)
        CROUTB(reg+1,(val>>8)&255);
 }
 
-static int SRINW(int reg)
-{
-       int result;
-       result=SRINB(reg);
-       result|=SRINB(reg+1)<<8;
-       return(result);
-}
-
 static void SROUTW(int reg,int val)
 {
        SROUTB(reg,val&255);
        SROUTB(reg+1,(val>>8)&255);
 }
 
-void DumpRegisters(void)
-{
-        int reg,val;
-#ifdef DEBUG_LOGFILE
-        if(logfile)
-        {
-                LOGWRITE("CRTC Register Dump:\n")
-                for(reg=0;reg<256;++reg)
-                {
-                        val=CRINB(reg);
-                        fprintf(logfile,"CR0x%2x: 0x%2x\n",reg,val);
-                }
-                LOGWRITE("SR Register Dump:\n")
-                for(reg=0;reg<256;++reg)
-                {
-                        val=SRINB(reg);
-                        fprintf(logfile,"SR0x%2x: 0x%2x\n",reg,val);
-                }
-        }
-#endif
-}
-/* --- */
-
 static vidix_capability_t cyberblade_cap =
 {
        "Trident CyberBlade i1 driver",
@@ -134,13 +90,6 @@ static vidix_capability_t cyberblade_cap =
        { 0, 0, 0, 0 }
 };
 
-
-unsigned int vixGetVersion(void)
-{
-       return(VIDIX_VERSION);
-}
-
-
 static unsigned short cyberblade_card_ids[] =
 {
        DEVICE_TRIDENT_CYBERBLADE_I7,
@@ -162,7 +111,7 @@ static int find_chip(unsigned chip_id)
   return -1;
 }
 
-int vixProbe(int verbose, int force)
+static int cyberblade_probe(int verbose, int force)
 {
        pciinfo_t lst[MAX_PCI_DEVICES];
        unsigned i,num_pci;
@@ -188,11 +137,13 @@ int vixProbe(int verbose, int force)
                                dname = pci_device_name(VENDOR_TRIDENT, lst[i].device);
                                dname = dname ? dname : "Unknown chip";
                                printf("[cyberblade] Found chip: %s\n", dname);
-                               if ((lst[i].command & PCI_COMMAND_IO) == 0)
+#if 0
+                                if ((lst[i].command & PCI_COMMAND_IO) == 0)
                                {
                                        printf("[cyberblade] Device is disabled, ignoring\n");
                                        continue;
                                }
+#endif
                                cyberblade_cap.device_id = lst[i].device;
                                err = 0;
                                memcpy(&pci_info, &lst[i], sizeof(pciinfo_t));
@@ -206,9 +157,9 @@ int vixProbe(int verbose, int force)
 }
 
 
-int vixInit(void)
+static int cyberblade_init(void)
 {
-       cyberblade_mem = map_phys_mem(pci_info.base0, 0x800000); 
+       cyberblade_mem = map_phys_mem(pci_info.base0, 0x800000);
        enable_app_io();
        save_colourkey[0]=SRINB(0x50);
        save_colourkey[1]=SRINB(0x51);
@@ -222,7 +173,7 @@ int vixInit(void)
        return 0;
 }
 
-void vixDestroy(void)
+static void cyberblade_destroy(void)
 {
        int protect;
 #ifdef DEBUG_LOGFILE
@@ -240,11 +191,11 @@ void vixDestroy(void)
        SROUTB(0x56,save_colourkey[5]);
        SROUTB(0x11, protect);
        disable_app_io();
-       unmap_phys_mem(cyberblade_mem, 0x800000); 
+       unmap_phys_mem(cyberblade_mem, 0x800000);
 }
 
 
-int vixGetCapability(vidix_capability_t *to)
+static int cyberblade_get_caps(vidix_capability_t *to)
 {
        memcpy(to, &cyberblade_cap, sizeof(vidix_capability_t));
        return 0;
@@ -266,19 +217,14 @@ static int is_supported_fourcc(uint32_t fourcc)
        }
 }
 
-int vixQueryFourcc(vidix_fourcc_t *to)
+static int cyberblade_query_fourcc(vidix_fourcc_t *to)
 {
        if(is_supported_fourcc(to->fourcc))
        {
-               to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP |
-                       VID_DEPTH_4BPP | VID_DEPTH_8BPP |
-                       VID_DEPTH_12BPP| VID_DEPTH_15BPP|
-                       VID_DEPTH_16BPP| VID_DEPTH_24BPP|
-                       VID_DEPTH_32BPP;
+               to->depth = VID_DEPTH_ALL;
                to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY;
                return 0;
        }
-       else
                to->depth = to->flags = 0;
        return ENOSYS;
 }
@@ -288,13 +234,13 @@ static int frames[VID_PLAY_MAXFRAMES];
 
 static vidix_grkey_t cyberblade_grkey;
 
-int vixGetGrKeys(vidix_grkey_t *grkey)
+static int cyberblade_get_gkeys(vidix_grkey_t *grkey)
 {
        memcpy(grkey, &cyberblade_grkey, sizeof(vidix_grkey_t));
-       return(0);
+       return 0;
 }
 
-int vixSetGrKeys(const vidix_grkey_t *grkey)
+static int cyberblade_set_gkeys(const vidix_grkey_t *grkey)
 {
        int pixfmt=CRINB(0x38);
        int protect;
@@ -325,23 +271,23 @@ int vixSetGrKeys(const vidix_grkey_t *grkey)
                SROUTB(0x56, 0x00); /* Colour Key Mask */
        }
        SROUTB(0x11,protect);
-       return(0);
+       return 0;
 }
 
 
-vidix_video_eq_t equal =
+static vidix_video_eq_t equal =
 {
        VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | VEQ_CAP_HUE,
        300, 100, 0, 0, 0, 0, 0, 0
 };
 
-int vixPlaybackGetEq( vidix_video_eq_t * eq)
+static int cyberblade_get_eq( vidix_video_eq_t * eq)
 {
   memcpy(eq,&equal,sizeof(vidix_video_eq_t));
   return 0;
 }
 
-int vixPlaybackSetEq( const vidix_video_eq_t * eq)
+static int cyberblade_set_eq( const vidix_video_eq_t * eq)
 {
        int br,sat,cr,protect;
        if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness;
@@ -381,14 +327,13 @@ int vixPlaybackSetEq( const vidix_video_eq_t * eq)
 
 static int YOffs,UOffs,VOffs;
 
-int vixConfigPlayback(vidix_playback_t *info)
+static int cyberblade_config_playback(vidix_playback_t *info)
 {
-       int shrink, zoom;
        int src_w, drw_w;
        int src_h, drw_h;
        int hscale,vscale;
        long base0;
-       int y_pitch, uv_pitch;
+       int y_pitch = 0, uv_pitch = 0;
        int protect=0;
        int layout=0;
        unsigned int i;
@@ -465,7 +410,7 @@ int vixConfigPlayback(vidix_playback_t *info)
        SROUTB(0x21, 0x34); /* Signature control */
        SROUTB(0x37, 0x30); /* Video key mode */
 
-        vixSetGrKeys(&cyberblade_grkey);
+        cyberblade_set_gkeys(&cyberblade_grkey);
 
        /* compute_scale_factor(&src_w, &drw_w, &shrink, &zoom); */
        {
@@ -496,19 +441,19 @@ int vixConfigPlayback(vidix_playback_t *info)
                        Overflow=CRINB(0x07);
                        VDisp |= (Overflow & 2) <<7;
                        VDisp |= (Overflow & 0x40) << 3;
+
                        TVHTotal=CRINB(0xe0)*8;
                        TVVTotal=CRINB(0xe6);
                        TVOverflow=CRINB(0xe7);
                        if(TVOverflow&0x20) TVVTotal|=512;
                        if(TVOverflow&0x01) TVVTotal|=256;
                        TVHTotal+=40; TVVTotal+=2;
+
                        TVHSyncStart=CRINB(0xe4)*8;
                        TVVSyncStart=CRINB(0xf0);
                        if(TVOverflow&0x80) TVVSyncStart|=512;
                        if(TVOverflow&0x04) TVVSyncStart|=256;
+
                        HWinStart=(TVHTotal-HDisp)&15;
                        HWinStart|=(HTotal-HDisp)&15;
                        HWinStart+=(TVHTotal-TVHSyncStart)-49;
@@ -520,7 +465,7 @@ int vixConfigPlayback(vidix_playback_t *info)
                }
                 VWinStart=(VTotal-VSync)-8;
 
-               printf("[cyberblade] HTotal: 0x%x, HSStart: 0x%x\n",HTotal,HSync); 
+               printf("[cyberblade] HTotal: 0x%x, HSStart: 0x%x\n",HTotal,HSync);
                printf("  VTotal: 0x%x, VStart: 0x%x\n",VTotal,VSync);
                tx1=HWinStart+info->dest.x;
                ty1=VWinStart+info->dest.y;
@@ -598,7 +543,7 @@ int vixConfigPlayback(vidix_playback_t *info)
                SROUTB(0x85, ((base0+info->offset.u) >> 19) &0xf); /* Upper 4 bits of start address */
        }
 
-       vixPlaybackSetEq(&equal);
+       cyberblade_set_eq(&equal);
 
        /* Protect hardware registers again */
        SROUTB(0x11, protect);
@@ -606,7 +551,7 @@ int vixConfigPlayback(vidix_playback_t *info)
 }
 
 
-int vixPlaybackOn(void)
+static int cyberblade_playback_on(void)
 {
        LOGWRITE("Enable overlay\n");
        CROUTB(0x8E, 0xd4); /* VDE Flags*/
@@ -615,19 +560,19 @@ int vixPlaybackOn(void)
 }
 
 
-int vixPlaybackOff(void)
+static int cyberblade_playback_off(void)
 {
-        LOGWRITE("Disable overlay\n"); 
+        LOGWRITE("Disable overlay\n");
        CROUTB(0x8E, 0xc4); /* VDE Flags*/
 
        return 0;
 }
 
 
-int vixPlaybackFrameSelect(unsigned int frame)
+static int cyberblade_frame_sel(unsigned int frame)
 {
        int protect;
-        LOGWRITE("Frame select\n"); 
+        LOGWRITE("Frame select\n");
        protect=SRINB(0x11);
        SROUTB(0x11, 0x92);
        /* Set overlay address to that of selected frame */
@@ -644,4 +589,20 @@ int vixPlaybackFrameSelect(unsigned int frame)
        return 0;
 }
 
-
+VDXDriver cyberblade_drv = {
+  "cyberblade",
+  NULL,
+  .probe = cyberblade_probe,
+  .get_caps = cyberblade_get_caps,
+  .query_fourcc = cyberblade_query_fourcc,
+  .init = cyberblade_init,
+  .destroy = cyberblade_destroy,
+  .config_playback = cyberblade_config_playback,
+  .playback_on = cyberblade_playback_on,
+  .playback_off = cyberblade_playback_off,
+  .frame_sel = cyberblade_frame_sel,
+  .get_eq = cyberblade_get_eq,
+  .set_eq = cyberblade_set_eq,
+  .get_gkey = cyberblade_get_gkeys,
+  .set_gkey = cyberblade_set_gkeys,
+};