<commit_before>/*
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 *
 * Graphics driver for ATI R200 based chipsets written by
 *             <NAME> <<EMAIL>>.  
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#include <dfb_types.h>
#include <directfb.h>

#include <direct/types.h>
#include <direct/messages.h>
#include <direct/util.h>

#include <core/coredefs.h>
#include <core/coretypes.h>
#include <core/screens.h>
#include <core/layer_control.h>
#include <core/system.h>

#include <fbdev/fbdev.h>

#include <misc/conf.h>

#include "r200.h"
#include "r200_regs.h"
#include "r200_mmio.h"



static DFBResult
crtc1InitScreen( CoreScreen           *screen,
                 GraphicsDevice       *device,
                 void                 *driver_data,
                 void                 *screen_data,
                 DFBScreenDescription *description )
{
     R200DriverData *rdrv = (R200DriverData*) driver_data;
     
     (void) rdrv;
     
     /* Set the screen capabilities. */
     description->caps = DSCCAPS_VSYNC | DSCCAPS_POWER_MANAGEMENT;

     /* Set the screen name. */
     snprintf( description->name,
               DFB_SCREEN_DESC_NAME_LENGTH, "Radeon200 Primary Screen" );
     
     return DFB_OK;
}

static DFBResult
crtc1SetPowerMode( CoreScreen         *screen,
                   void               *driver_data,
                   void               *screen_data,
                   DFBScreenPowerMode  mode )
{
     FBDev *fbdev = dfb_system_data();
     int    level;

     switch (mode) {
          case DSPM_OFF:
               level = 4;
               break;
          case DSPM_SUSPEND:
               level = 3;
               break;
          case DSPM_STANDBY:
               level = 2;
               break;
          case DSPM_ON:
               level = 0;
               break;
          default:
               return DFB_UNSUPPORTED;
     }

     if (ioctl( fbdev->fd, FBIOBLANK, level ) < 0) {
          D_PERROR( "DirectFB/R200: Display blanking failed!\n" );
          return errno2result( errno );
     }

     return DFB_OK;
}

static DFBResult
crtc1WaitVSync( CoreScreen *screen,
                void       *driver_data,
                void       *layer_data )
{
     R200DriverData  *rdrv = (R200DriverData*) driver_data;
     volatile __u8   *mmio = rdrv->mmio_base; 
     int              i;
     
     if (dfb_config->pollvsync_none)
          return DFB_OK;
          
     r200_out32( mmio, GEN_INT_STATUS, VSYNC_INT_AK );
     for (i = 0; i < 20000000; i++) {
          if (r200_in32( mmio, GEN_INT_STATUS ) & VSYNC_INT)
               break;
     }

     return DFB_OK;
}

static DFBResult
crtc1GetScreenSize( CoreScreen *screen,
                    void       *driver_data,
                    void       *screen_data,
                    int        *ret_width,
                    int        *ret_height )
{
     R200DriverData *rdrv    = (R200DriverData*) driver_data;
     volatile __u8  *mmio    = rdrv->mmio_base;
     __u32           h_total;
     __u32           v_total;
     __u32           xres;
     __u32           yres;

     h_total = r200_in32( mmio, CRTC_H_TOTAL_DISP );
     v_total = r200_in32( mmio, CRTC_V_TOTAL_DISP );
     
     xres = ((h_total >> 16) + 1) << 3;
     yres = ((v_total >> 16) + 1);

     D_DEBUG( "DirectFB/R200: detected screen size %dx%d.\n", xres, yres );

     *ret_width  = xres;
     *ret_height = yres;
     
     return DFB_OK;
}


ScreenFuncs R200PrimaryScreenFuncs = {
     .InitScreen    = crtc1InitScreen,<commit_msg>Sleep while waiting for vertical retrace.<commit_after>/*
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 *
 * Graphics driver for ATI R200 based chipsets written by
 *             <NAME> <<EMAIL>>.  
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#include <dfb_types.h>
#include <directfb.h>

#include <direct/types.h>
#include <direct/messages.h>
#include <direct/util.h>

#include <core/coredefs.h>
#include <core/coretypes.h>
#include <core/screens.h>
#include <core/layer_control.h>
#include <core/system.h>

#include <fbdev/fbdev.h>

#include <misc/conf.h>

#include "r200.h"
#include "r200_regs.h"
#include "r200_mmio.h"



static DFBResult
crtc1InitScreen( CoreScreen           *screen,
                 GraphicsDevice       *device,
                 void                 *driver_data,
                 void                 *screen_data,
                 DFBScreenDescription *description )
{
     R200DriverData *rdrv = (R200DriverData*) driver_data;
     
     (void) rdrv;
     
     /* Set the screen capabilities. */
     description->caps = DSCCAPS_VSYNC | DSCCAPS_POWER_MANAGEMENT;

     /* Set the screen name. */
     snprintf( description->name,
               DFB_SCREEN_DESC_NAME_LENGTH, "Radeon200 Primary Screen" );
     
     return DFB_OK;
}

static DFBResult
crtc1SetPowerMode( CoreScreen         *screen,
                   void               *driver_data,
                   void               *screen_data,
                   DFBScreenPowerMode  mode )
{
     FBDev *fbdev = dfb_system_data();
     int    level;

     switch (mode) {
          case DSPM_OFF:
               level = 4;
               break;
          case DSPM_SUSPEND:
               level = 3;
               break;
          case DSPM_STANDBY:
               level = 2;
               break;
          case DSPM_ON:
               level = 0;
               break;
          default:
               return DFB_UNSUPPORTED;
     }

     if (ioctl( fbdev->fd, FBIOBLANK, level ) < 0) {
          D_PERROR( "DirectFB/R200/Crtc1: display blanking failed!\n" );
          return errno2result( errno );
     }

     return DFB_OK;
}

static DFBResult
crtc1WaitVSync( CoreScreen *screen,
                void       *driver_data,
                void       *screen_data )
{
     R200DriverData *rdrv = (R200DriverData*) driver_data;
     volatile __u8  *mmio = rdrv->mmio_base; 
     int             i;
     
     if (dfb_config->pollvsync_none)
          return DFB_OK;
          
     r200_out32( mmio, GEN_INT_STATUS, VSYNC_INT_AK );
     
     for (i = 0; i < 2000000; i++) {
          struct timespec t = { 0, 0 };     
          
          if (r200_in32( mmio, GEN_INT_STATUS ) & VSYNC_INT)
               break;
          nanosleep( &t, NULL );
     }

     return DFB_OK;
}

static DFBResult
crtc1GetScreenSize( CoreScreen *screen,
                    void       *driver_data,
                    void       *screen_data,
                    int        *ret_width,
                    int        *ret_height )
{
     R200DriverData *rdrv    = (R200DriverData*) driver_data;
     volatile __u8  *mmio    = rdrv->mmio_base;
     __u32           h_total;
     __u32           v_total;
     __u32           xres;
     __u32           yres;

     h_total = r200_in32( mmio, CRTC_H_TOTAL_DISP );
     v_total = r200_in32( mmio, CRTC_V_TOTAL_DISP );
     
     xres = ((h_total >> 16) + 1) << 3;
     yres = ((v_total >> 16) + 1);

     D_DEBUG( "DirectFB/R200/Crtc1: "
              "detected screen size %dx%d.\n", xres, yres );

     *ret_width  = xres;
     *ret_height = yres;
     
     return DFB_OK;
}


ScreenFuncs R200PrimaryScreenFuncs = {
     .InitScreen    = crtc1InitScreen,
{'fraction_non_alphanumeric': 0.09225755702887965, 'fraction_numerical': 0.026856950219125743, 'mean_word_length': 1.893368010403121, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7030805', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2816, 'n_words': 768}