lx_panel.c revision 7aef237f
1/* Copyright (c) 2008 Advanced Micro Devices, Inc.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 *
21 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
22 * contributors may be used to endorse or promote products derived from this
23 * software without specific prior written permission.
24 */
25
26/* Reference: Video Graphics Suite Specification:
27 * VG Config Register (0x00) page 16
28 * VG FP Register (0x02) page 18
29 */
30
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <stdio.h>
36
37#include "xf86.h"
38#include "compiler.h"
39#include "xf86Modes.h"
40#include "geode.h"
41
42#define LX_READ_VG(reg) \
43                (outw(0xAC1C,0xFC53), outw(0xAC1C,0x0200|(reg)), inw(0xAC1E))
44
45/* This is borrowed from xerver/hw/xfree86/modes */
46
47#define MODEPREFIX NULL, NULL, NULL, 0, M_T_DRIVER
48#define MODESUFFIX 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0
49
50DisplayModeRec lx_panel_modes[] = {
51    {MODEPREFIX, 31200, 320, 354, 384, 400, 0, 240, 249, 253, 260, 0,
52	V_NHSYNC | V_NVSYNC, MODESUFFIX}
53    ,				       /* 320x200@75 */
54    {MODEPREFIX, 25175, 640, 656, 744, 800, 0, 480, 490, 492, 525, 0,
55	V_NHSYNC | V_NVSYNC, MODESUFFIX}
56    ,				       /* 640x480@60 */
57    {MODEPREFIX, 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0,
58	V_NHSYNC | V_NVSYNC, MODESUFFIX}
59    ,				       /* 880x600@60 */
60    {MODEPREFIX, 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0,
61	V_NHSYNC | V_NVSYNC, MODESUFFIX}
62    ,				       /* 1024x768@60 */
63    {MODEPREFIX, 81600, 1152, 1216, 1336, 1520, 0, 864, 865, 868, 895, 0,
64	V_NHSYNC | V_NVSYNC, MODESUFFIX}
65    ,				       /* 1152x864@60 */
66    {MODEPREFIX, 108000, 1280, 1328, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
67	V_NHSYNC | V_NVSYNC, MODESUFFIX}
68    ,				       /* 1280x1024@60 */
69    {MODEPREFIX, 162000, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
70	V_NHSYNC | V_NVSYNC, MODESUFFIX}
71    ,				       /* 1600x1200@60 */
72    {MODEPREFIX, 48960, 1024, 1064, 1168, 1312, 0, 600, 601, 604, 622, 0,
73        V_NHSYNC | V_NVSYNC, MODESUFFIX}
74    ,				       /* 1024x600@60 wide panels */
75};
76
77/* Get the legacy panel size from VSA, and return the associated mode rec */
78
79DisplayModePtr
80LXGetLegacyPanelMode(ScrnInfoPtr pScrni)
81{
82    unsigned short reg = LX_READ_VG(0x00);
83    unsigned char ret = (reg >> 8) & 0x07;
84    if ((ret == 1 || ret == 5)) {
85
86	reg = LX_READ_VG(0x02);
87	ret = (reg >> 3) & 0x07;
88
89	/* FIXME: 7 is reserved in default. We use this value to support
90 	 * wide screen resolution 1024x600@80 now for panel. If you want to use
91 	 * that resolution, please assign ret to 7 manually here:
92 	 * "reg = 7"
93 	 * The user can use this entry for other wide screen resolutions.
94	 */
95
96	if (ret < 8) {
97	    xf86DrvMsg(pScrni->scrnIndex, X_INFO,
98		" VSA Panel Mode is: %dx%d, pixel clock freq(kHz) is %d\n",
99		lx_panel_modes[ret].HDisplay, lx_panel_modes[ret].VDisplay,
100		lx_panel_modes[ret].Clock);
101	    return &lx_panel_modes[ret];
102	}
103
104    }
105
106    return NULL;
107}
108
109/* Construct a moderec from the specified panel mode */
110
111DisplayModePtr
112LXGetManualPanelMode(char *modestr)
113{
114    int clock;
115    int hactive, hsstart, hsend, htotal;
116    int vactive, vsstart, vsend, vtotal;
117    DisplayModePtr mode;
118    char sname[32];
119
120    int ret = sscanf(modestr, "%d %d %d %d %d %d %d %d %d",
121	&clock,
122	&hactive, &hsstart, &hsend, &htotal,
123	&vactive, &vsstart, &vsend, &vtotal);
124
125    if (ret != 9)
126	return NULL;
127
128    mode = xnfcalloc(1, sizeof(DisplayModeRec));
129
130    if (mode == NULL)
131	return NULL;
132
133    sprintf(sname, "%dx%d", hactive, vactive);
134
135    mode->name = xnfalloc(strlen(sname) + 1);
136    strcpy(mode->name, sname);
137
138    mode->type = M_T_DRIVER | M_T_PREFERRED;
139    mode->Clock = clock;
140    mode->HDisplay = hactive;
141    mode->HSyncStart = hsstart;
142    mode->HSyncEnd = hsend;
143    mode->HTotal = htotal;
144    mode->VDisplay = vactive;
145    mode->VSyncStart = vsstart;
146    mode->VSyncEnd = vsend;
147    mode->VTotal = vtotal;
148
149    mode->prev = mode->next = NULL;
150
151    return mode;
152}
153