1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/panel/pnl_bios.c,v 1.2 2002/12/11 22:51:02 dawes Exp $ */
2/*
3 * $Workfile: pnl_bios.c $
4 * $Revision: 1.1.1.1 $
5 *
6 * File Contents: This file panel functions which query for the BIOS for current FP
7 *                Paramters.
8 *
9 * SubModule:     Geode FlatPanel library
10 *
11 */
12
13/*
14 * NSC_LIC_ALTERNATIVE_PREAMBLE
15 *
16 * Revision 1.0
17 *
18 * National Semiconductor Alternative GPL-BSD License
19 *
20 * National Semiconductor Corporation licenses this software
21 * ("Software"):
22 *
23 * Panel Library
24 *
25 * under one of the two following licenses, depending on how the
26 * Software is received by the Licensee.
27 *
28 * If this Software is received as part of the Linux Framebuffer or
29 * other GPL licensed software, then the GPL license designated
30 * NSC_LIC_GPL applies to this Software; in all other circumstances
31 * then the BSD-style license designated NSC_LIC_BSD shall apply.
32 *
33 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */
34
35/* NSC_LIC_BSD
36 *
37 * National Semiconductor Corporation Open Source License for
38 *
39 * Panel Library
40 *
41 * (BSD License with Export Notice)
42 *
43 * Copyright (c) 1999-2001
44 * National Semiconductor Corporation.
45 * All rights reserved.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 *
51 *   * Redistributions of source code must retain the above copyright
52 *     notice, this list of conditions and the following disclaimer.
53 *
54 *   * Redistributions in binary form must reproduce the above
55 *     copyright notice, this list of conditions and the following
56 *     disclaimer in the documentation and/or other materials provided
57 *     with the distribution.
58 *
59 *   * Neither the name of the National Semiconductor Corporation nor
60 *     the names of its contributors may be used to endorse or promote
61 *     products derived from this software without specific prior
62 *     written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
65 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
66 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
67 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
68 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
69 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
71 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
72 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
73 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
74 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
76 * OF SUCH DAMAGE.
77 *
78 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
79 * YOUR JURISDICTION. It is licensee's responsibility to comply with
80 * any export regulations applicable in licensee's jurisdiction. Under
81 * CURRENT (2001) U.S. export regulations this software
82 * is eligible for export from the U.S. and can be downloaded by or
83 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
84 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
85 * Syria, Sudan, Afghanistan and any other country to which the U.S.
86 * has embargoed goods and services.
87 *
88 * END_NSC_LIC_BSD */
89
90/* NSC_LIC_GPL
91 *
92 * National Semiconductor Corporation Gnu General Public License for
93 *
94 * Panel Library
95 *
96 * (GPL License with Export Notice)
97 *
98 * Copyright (c) 1999-2001
99 * National Semiconductor Corporation.
100 * All rights reserved.
101 *
102 * Redistribution and use in source and binary forms, with or without
103 * modification, are permitted under the terms of the GNU General
104 * Public License as published by the Free Software Foundation; either
105 * version 2 of the License, or (at your option) any later version
106 *
107 * In addition to the terms of the GNU General Public License, neither
108 * the name of the National Semiconductor Corporation nor the names of
109 * its contributors may be used to endorse or promote products derived
110 * from this software without specific prior written permission.
111 *
112 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
113 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
114 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
115 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
116 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
117 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
119 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
120 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
121 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
122 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
123 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
124 * OF SUCH DAMAGE. See the GNU General Public License for more details.
125 *
126 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
127 * YOUR JURISDICTION. It is licensee's responsibility to comply with
128 * any export regulations applicable in licensee's jurisdiction. Under
129 * CURRENT (2001) U.S. export regulations this software
130 * is eligible for export from the U.S. and can be downloaded by or
131 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
132 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
133 * Syria, Sudan, Afghanistan and any other country to which the U.S.
134 * has embargoed goods and services.
135 *
136 * You should have received a copy of the GNU General Public License
137 * along with this file; if not, write to the Free Software Foundation,
138 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
139 *
140 * END_NSC_LIC_GPL */
141
142#include "panel.h"
143
144#if defined(_WIN32)			/* windows */
145extern unsigned long gfx_cpu_version;
146extern void gfx_outw(unsigned short port, unsigned short data);
147extern unsigned short gfx_inw(unsigned short port);
148#endif
149
150#define SOFTVGA_DISPLAY_ENABLE   0x50
151#define SOFTVGA_FPRESOLUTION     0x52
152#define SOFTVGA_FPCLOCKFREQUENCY 0x54
153
154/* SOFTVG VIRTUAL REGISTER DEFINITIONS */
155
156#define VR_INDEX                0xAC1C
157#define VR_DATA                 0xAC1E
158#define VR_UNLOCK               0xFC53
159#define VRC_VG                  0x0002	/* SoftVG Virtual Register Class    */
160#define VG_MEM_SIZE             0x0000	/* MemSize Virtual Register */
161#define FP_DETECT_MASK          0x8000
162
163#define VG_FP_TYPE      0x0002		/* Flat Panel Info Virtual Register */
164
165#define FP_DEV_MASK     0x0003		/* Flat Panel type */
166#define FP_TYPE_SSTN	0x0000		/* SSTN panel type value */
167#define FP_TYPE_DSTN	0x0001		/* DSTN panel type value */
168#define FP_TYPE_TFT		0x0002	/* TFT panel type value */
169#define FP_TYPE_LVDS	0x0003		/* LVDS panel type value */
170
171#define FP_RESOLUTION_MASK      0x0038
172#define FP_RES_6X4		0x0000	/* 640x480 resolution value */
173#define FP_RES_8X6		0x0008	/* 800x600 resolution value */
174#define FP_RES_10X7		0x0010	/* 1024x768 resolution value */
175#define FP_RES_12X10	0x0018		/* 1280x1024 resolution value */
176#define FP_RES_16X12	0x0020		/* 1600x1200 resolution value */
177
178#define FP_WIDTH_MASK   0x01C0
179#define FP_WIDTH_8		0x0000	/* 8 bit data bus width */
180#define FP_WIDTH_9		0x0040	/* 9 bit data bus width */
181#define FP_WIDTH_12		0x0080	/* 12 bit data bus width */
182#define FP_WIDTH_18		0x00C0	/* 18 bit data bus width */
183#define FP_WIDTH_24		0x0100	/* 24 bit data bus width */
184#define FP_WIDTH_16		0x0140	/* 16 bit data bus width - 16 bit Mono DSTN only */
185
186#define FP_COLOR_MASK   0x0200
187#define FP_COLOR_COLOR	0x0000		/* Color panel */
188#define FP_COLOR_MONO	0x0200		/* Mono Panel */
189
190#define FP_PPC_MASK     0x0400
191#define FP_PPC_1PPC		0x0000	/* One pixel per clock */
192#define FP_PPC_2PPC		0x0400	/* Two pixels per clock */
193
194#define FP_HPOL_MASK    0x0800
195#define	FP_H_POL_LGH	0x0000		/* HSync at panel, normally low, active high */
196#define FP_H_POL_HGL	0x0800		/* HSync at panel, normally high, active low */
197
198#define FP_VPOL_MASK    0x1000
199#define FP_V_POL_LGH	0x0000		/* VSync at panel, normally low, active high */
200#define FP_V_POL_HGL	0x1000		/* VSync at panel, normally high, active low */
201
202#define FP_REF_MASK     0xD000
203#define FP_REF_60		0x0000	/* 60Hz refresh rate */
204#define FP_REF_65		0x2000	/* 65Hz refresh rate */
205#define FP_REF_70		0x4000	/* 70Hz refresh rate */
206#define FP_REF_72		0x6000	/* 72Hz refresh rate */
207#define FP_REF_75		0x8000	/* 75Hz refresh rate */
208#define FP_REF_85		0xA000	/* 85Hz refresh rate */
209
210/*-----------------------------------------------------------------
211 * Pnl_IsPanelEnabledInBIOS
212 *
213 * Description:	This function specifies whether the panel is enabled
214 *				by the BIOS or not.
215 *  parameters: none.
216 *      return: 1 - Enabled, 0 - Disabled
217 *-----------------------------------------------------------------*/
218int
219Pnl_IsPanelEnabledInBIOS(void)
220{
221   unsigned char ret = 0;
222
223   if ((gfx_cpu_version & 0xFF) == GFX_CPU_REDCLOUD) {
224      unsigned short data;
225
226      gfx_outw(VR_INDEX, VR_UNLOCK);
227      gfx_outw(VR_INDEX, (VRC_VG << 8) | VG_MEM_SIZE);
228      data = gfx_inw(VR_DATA);
229      if (data & FP_DETECT_MASK)
230	 ret = 1;
231   } else {
232      unsigned short crtcindex, crtcdata;
233
234      crtcindex = (gfx_inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
235      crtcdata = crtcindex + 1;
236
237      /* CHECK DisplayEnable Reg in SoftVGA */
238
239      gfx_outb(crtcindex, (unsigned char)SOFTVGA_DISPLAY_ENABLE);
240      ret = gfx_inb(crtcdata);
241   }
242
243   return (ret & 0x1);
244}
245
246/*-----------------------------------------------------------------
247 * Pnl_GetPanelInfoFromBIOS
248 *
249 * Description:	This function queries the panel information from
250 *              the BIOS.
251 *  parameters:
252 *        xres: width of the panel configured
253 *        yres: height of the panel configured
254 *         bpp: depth of the panel configured
255 *          hz: vertical frequency of the panel configured
256 *      return: none
257 *-----------------------------------------------------------------*/
258void
259Pnl_GetPanelInfoFromBIOS(int *xres, int *yres, int *bpp, int *hz)
260{
261   unsigned short crtcindex, crtcdata;
262   unsigned short ret;
263
264   if ((gfx_cpu_version & 0xFF) == GFX_CPU_REDCLOUD) {
265      gfx_outw(VR_INDEX, VR_UNLOCK);
266      gfx_outw(VR_INDEX, (VRC_VG << 8) | VG_FP_TYPE);
267      ret = gfx_inw(VR_DATA);
268      switch (ret & FP_RESOLUTION_MASK) {
269      case FP_RES_6X4:
270	 *xres = 640;
271	 *yres = 480;
272	 break;
273      case FP_RES_8X6:
274	 *xres = 800;
275	 *yres = 600;
276	 break;
277      case FP_RES_10X7:
278	 *xres = 1024;
279	 *yres = 768;
280	 break;
281      case FP_RES_12X10:
282	 *xres = 1280;
283	 *yres = 1024;
284	 break;
285      case FP_RES_16X12:
286	 *xres = 1600;
287	 *yres = 1200;
288	 break;
289      }
290
291      switch (ret & FP_WIDTH_MASK) {
292      case FP_WIDTH_8:
293	 *bpp = 8;
294	 break;
295      case FP_WIDTH_9:
296	 *bpp = 9;
297	 break;
298      case FP_WIDTH_12:
299	 *bpp = 12;
300	 break;
301      case FP_WIDTH_18:
302	 *bpp = 18;
303	 break;
304      case FP_WIDTH_24:
305	 *bpp = 24;
306	 break;
307      case FP_WIDTH_16:
308	 *bpp = 16;
309	 break;
310      }
311
312      switch (ret & FP_REF_MASK) {
313      case FP_REF_60:
314	 *hz = 60;
315	 break;
316      case FP_REF_65:
317	 *hz = 65;
318	 break;
319      case FP_REF_70:
320	 *hz = 70;
321	 break;
322      case FP_REF_72:
323	 *hz = 72;
324	 break;
325      case FP_REF_75:
326	 *hz = 75;
327	 break;
328      case FP_REF_85:
329	 *hz = 85;
330	 break;
331      }
332
333   } else {
334      crtcindex = (gfx_inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
335      crtcdata = crtcindex + 1;
336
337      /* CHECK FPResolution Reg in SoftVGA */
338
339      gfx_outb(crtcindex, (unsigned char)SOFTVGA_FPRESOLUTION);
340      ret = gfx_inb(crtcdata);
341
342      switch (ret & 0x3) {
343      case 0:
344	 *xres = 640;
345	 *yres = 480;
346	 break;
347      case 1:
348	 *xres = 800;
349	 *yres = 600;
350	 break;
351      case 2:
352	 *xres = 1024;
353	 *yres = 768;
354	 break;
355      }
356
357      switch ((ret >> 4) & 0x3) {
358      case 0:
359	 *bpp = 12;
360	 break;
361      case 1:
362	 *bpp = 18;
363	 break;
364      case 2:
365	 *bpp = 16;
366	 break;
367      case 3:
368	 *bpp = 8;
369	 break;
370      }
371
372      /* CHECK FPClockFrequency Reg in SoftVGA */
373
374      gfx_outb(crtcindex, (unsigned char)SOFTVGA_FPCLOCKFREQUENCY);
375      *hz = gfx_inb(crtcdata);
376   }
377}
378