xref: /haiku/src/add-ons/accelerants/et6x00/SetDisplayMode.c (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*****************************************************************************\
2  * Tseng Labs ET6000, ET6100 and ET6300 graphics driver for BeOS 5.
3  * Copyright (c) 2003-2004, Evgeniy Vladimirovich Bobkov.
4 \*****************************************************************************/
5 
6 #include "GlobalData.h"
7 #include "generic.h"
8 #include <sys/ioctl.h>
9 
10 
11 /*****************************************************************************/
12 /*
13  * The code to actually configure the display.
14  */
15 static status_t doSetDisplayMode(display_mode *dm) {
16 ET6000DisplayMode mode;
17 
18     mode.magic = ET6000_PRIVATE_DATA_MAGIC;
19     mode.mode = *dm;
20     mode.pciConfigSpace = si->pciConfigSpace;
21 
22     return ioctl(fd, ET6000_SET_DISPLAY_MODE, &mode, sizeof(mode));
23 }
24 /*****************************************************************************/
25 /*
26  * The exported mode setting routine. First validate the mode,
27  * then call our private routine to hammer the registers.
28  */
29 status_t SET_DISPLAY_MODE(display_mode *mode_to_set) {
30 display_mode bounds, target;
31 status_t result;
32 uint8 bpp;
33 
34     /* ask for the specific mode */
35     target = bounds = *mode_to_set;
36     if (PROPOSE_DISPLAY_MODE(&target, &bounds, &bounds) != B_OK) /* ==B_ERROR???/// */
37 	return B_ERROR;
38 
39     result = doSetDisplayMode(&target);
40 
41     if (result == B_OK) {
42         switch (target.space) {
43             case B_RGB24_LITTLE:
44             case B_RGB24_BIG:
45                 bpp = 3;
46                 break;
47             case B_RGB16_LITTLE:
48             case B_RGB16_BIG:
49             case B_RGB15_LITTLE:
50             case B_RGB15_BIG:
51                 bpp = 2;
52                 break;
53 			default:
54 				return B_BAD_VALUE;
55         }
56         si->fbc.bytes_per_row = target.virtual_width * bpp;
57         si->dm = target;
58         si->bytesPerPixel = bpp;
59         et6000aclInit(bpp);
60     }
61 
62     return result;
63 }
64 /*****************************************************************************/
65