171d7fec4Smrg/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/gfx/init_gu1.c,v 1.1 2002/12/10 15:12:27 alanh Exp $ */
271d7fec4Smrg/*
371d7fec4Smrg * $Workfile: init_gu1.c $
471d7fec4Smrg *
571d7fec4Smrg * This file contains routines used in the initialization of Geode-family
671d7fec4Smrg * processors.
771d7fec4Smrg *
871d7fec4Smrg * NSC_LIC_ALTERNATIVE_PREAMBLE
971d7fec4Smrg *
1071d7fec4Smrg * Revision 1.0
1171d7fec4Smrg *
1271d7fec4Smrg * National Semiconductor Alternative GPL-BSD License
1371d7fec4Smrg *
1471d7fec4Smrg * National Semiconductor Corporation licenses this software
1571d7fec4Smrg * ("Software"):
1671d7fec4Smrg *
1771d7fec4Smrg *      Durango
1871d7fec4Smrg *
1971d7fec4Smrg * under one of the two following licenses, depending on how the
2071d7fec4Smrg * Software is received by the Licensee.
2171d7fec4Smrg *
2271d7fec4Smrg * If this Software is received as part of the Linux Framebuffer or
2371d7fec4Smrg * other GPL licensed software, then the GPL license designated
2471d7fec4Smrg * NSC_LIC_GPL applies to this Software; in all other circumstances
2571d7fec4Smrg * then the BSD-style license designated NSC_LIC_BSD shall apply.
2671d7fec4Smrg *
2771d7fec4Smrg * END_NSC_LIC_ALTERNATIVE_PREAMBLE */
2871d7fec4Smrg
2971d7fec4Smrg/* NSC_LIC_BSD
3071d7fec4Smrg *
3171d7fec4Smrg * National Semiconductor Corporation Open Source License for Durango
3271d7fec4Smrg *
3371d7fec4Smrg * (BSD License with Export Notice)
3471d7fec4Smrg *
3571d7fec4Smrg * Copyright (c) 1999-2001
3671d7fec4Smrg * National Semiconductor Corporation.
3771d7fec4Smrg * All rights reserved.
3871d7fec4Smrg *
3971d7fec4Smrg * Redistribution and use in source and binary forms, with or without
4071d7fec4Smrg * modification, are permitted provided that the following conditions
4171d7fec4Smrg * are met:
4271d7fec4Smrg *
4371d7fec4Smrg *   * Redistributions of source code must retain the above copyright
4471d7fec4Smrg *     notice, this list of conditions and the following disclaimer.
4571d7fec4Smrg *
4671d7fec4Smrg *   * Redistributions in binary form must reproduce the above
4771d7fec4Smrg *     copyright notice, this list of conditions and the following
4871d7fec4Smrg *     disclaimer in the documentation and/or other materials provided
4971d7fec4Smrg *     with the distribution.
5071d7fec4Smrg *
5171d7fec4Smrg *   * Neither the name of the National Semiconductor Corporation nor
5271d7fec4Smrg *     the names of its contributors may be used to endorse or promote
5371d7fec4Smrg *     products derived from this software without specific prior
5471d7fec4Smrg *     written permission.
5571d7fec4Smrg *
5671d7fec4Smrg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5771d7fec4Smrg * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5871d7fec4Smrg * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
5971d7fec4Smrg * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
6071d7fec4Smrg * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
6171d7fec4Smrg * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6271d7fec4Smrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
6371d7fec4Smrg * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6471d7fec4Smrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
6571d7fec4Smrg * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
6671d7fec4Smrg * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
6771d7fec4Smrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
6871d7fec4Smrg * OF SUCH DAMAGE.
6971d7fec4Smrg *
7071d7fec4Smrg * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
7171d7fec4Smrg * YOUR JURISDICTION. It is licensee's responsibility to comply with
7271d7fec4Smrg * any export regulations applicable in licensee's jurisdiction. Under
7371d7fec4Smrg * CURRENT (2001) U.S. export regulations this software
7471d7fec4Smrg * is eligible for export from the U.S. and can be downloaded by or
7571d7fec4Smrg * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
7671d7fec4Smrg * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
7771d7fec4Smrg * Syria, Sudan, Afghanistan and any other country to which the U.S.
7871d7fec4Smrg * has embargoed goods and services.
7971d7fec4Smrg *
8071d7fec4Smrg * END_NSC_LIC_BSD */
8171d7fec4Smrg
8271d7fec4Smrg/* NSC_LIC_GPL
8371d7fec4Smrg *
8471d7fec4Smrg * National Semiconductor Corporation Gnu General Public License for Durango
8571d7fec4Smrg *
8671d7fec4Smrg * (GPL License with Export Notice)
8771d7fec4Smrg *
8871d7fec4Smrg * Copyright (c) 1999-2001
8971d7fec4Smrg * National Semiconductor Corporation.
9071d7fec4Smrg * All rights reserved.
9171d7fec4Smrg *
9271d7fec4Smrg * Redistribution and use in source and binary forms, with or without
9371d7fec4Smrg * modification, are permitted under the terms of the GNU General
9471d7fec4Smrg * Public License as published by the Free Software Foundation; either
9571d7fec4Smrg * version 2 of the License, or (at your option) any later version
9671d7fec4Smrg *
9771d7fec4Smrg * In addition to the terms of the GNU General Public License, neither
9871d7fec4Smrg * the name of the National Semiconductor Corporation nor the names of
9971d7fec4Smrg * its contributors may be used to endorse or promote products derived
10071d7fec4Smrg * from this software without specific prior written permission.
10171d7fec4Smrg *
10271d7fec4Smrg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10371d7fec4Smrg * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10471d7fec4Smrg * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
10571d7fec4Smrg * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
10671d7fec4Smrg * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
10771d7fec4Smrg * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
10871d7fec4Smrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
10971d7fec4Smrg * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
11071d7fec4Smrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
11171d7fec4Smrg * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
11271d7fec4Smrg * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
11371d7fec4Smrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
11471d7fec4Smrg * OF SUCH DAMAGE. See the GNU General Public License for more details.
11571d7fec4Smrg *
11671d7fec4Smrg * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
11771d7fec4Smrg * YOUR JURISDICTION. It is licensee's responsibility to comply with
11871d7fec4Smrg * any export regulations applicable in licensee's jurisdiction. Under
11971d7fec4Smrg * CURRENT (2001) U.S. export regulations this software
12071d7fec4Smrg * is eligible for export from the U.S. and can be downloaded by or
12171d7fec4Smrg * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
12271d7fec4Smrg * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
12371d7fec4Smrg * Syria, Sudan, Afghanistan and any other country to which the U.S.
12471d7fec4Smrg * has embargoed goods and services.
12571d7fec4Smrg *
12671d7fec4Smrg * You should have received a copy of the GNU General Public License
12771d7fec4Smrg * along with this file; if not, write to the Free Software Foundation,
12871d7fec4Smrg * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12971d7fec4Smrg *
13071d7fec4Smrg * END_NSC_LIC_GPL */
13171d7fec4Smrg
13271d7fec4Smrgunsigned char gfx_gxm_config_read(unsigned char index);
13371d7fec4Smrgunsigned long gu1_get_core_freq(void);
13471d7fec4Smrgunsigned long gu1_detect_cpu(void);
13571d7fec4Smrgunsigned long gu1_detect_video(void);
13671d7fec4Smrgunsigned long gu1_get_cpu_register_base(void);
13771d7fec4Smrgunsigned long gu1_get_graphics_register_base(void);
13871d7fec4Smrgunsigned long gu1_get_frame_buffer_base(void);
13971d7fec4Smrgunsigned long gu1_get_frame_buffer_size(void);
14071d7fec4Smrgunsigned long gu1_get_vid_register_base(void);
14171d7fec4Smrgunsigned long gu1_get_vip_register_base(void);
14271d7fec4Smrg
14371d7fec4Smrg/*-----------------------------------------------------------------------------
14471d7fec4Smrg * gfx_gxm_config_read
14571d7fec4Smrg *
14671d7fec4Smrg * This routine reads the value of the specified GXm configuration register.
14771d7fec4Smrg *-----------------------------------------------------------------------------
14871d7fec4Smrg */
14971d7fec4Smrgunsigned char
15071d7fec4Smrggfx_gxm_config_read(unsigned char index)
15171d7fec4Smrg{
15271d7fec4Smrg   unsigned char value = 0xFF;
15371d7fec4Smrg   unsigned char lock;
15471d7fec4Smrg
15571d7fec4Smrg   OUTB(0x22, GXM_CONFIG_CCR3);
15671d7fec4Smrg   lock = INB(0x23);
15771d7fec4Smrg   OUTB(0x22, GXM_CONFIG_CCR3);
15871d7fec4Smrg   OUTB(0x23, (unsigned char)(lock | 0x10));
15971d7fec4Smrg   OUTB(0x22, index);
16071d7fec4Smrg   value = INB(0x23);
16171d7fec4Smrg   OUTB(0x22, GXM_CONFIG_CCR3);
16271d7fec4Smrg   OUTB(0x23, lock);
16371d7fec4Smrg   return (value);
16471d7fec4Smrg}
16571d7fec4Smrg
16671d7fec4Smrg/*-----------------------------------------------------------------------------
16771d7fec4Smrg * gfx_get_core_freq
16871d7fec4Smrg *
16971d7fec4Smrg * This routine returns the core clock frequency of a GXm if valid jumper settings are
17071d7fec4Smrg * detected; 0 if not. It assumes that a 33.3 MHz PCI clock is being used.
17171d7fec4Smrg *-----------------------------------------------------------------------------
17271d7fec4Smrg */
17371d7fec4Smrg#if GFX_INIT_DYNAMIC
17471d7fec4Smrgunsigned long
17571d7fec4Smrggu1_get_core_freq(void)
17671d7fec4Smrg#else
17771d7fec4Smrgunsigned long
17871d7fec4Smrggfx_get_core_freq(void)
17971d7fec4Smrg#endif
18071d7fec4Smrg{
18171d7fec4Smrg   unsigned char dir0, dir1;
18271d7fec4Smrg
18371d7fec4Smrg   dir0 = gfx_gxm_config_read(GXM_CONFIG_DIR0) & 0x0F;
18471d7fec4Smrg   dir1 = gfx_gxm_config_read(GXM_CONFIG_DIR1);
18571d7fec4Smrg
18671d7fec4Smrg   /* REVISION 4.0 AND UP */
18771d7fec4Smrg
18871d7fec4Smrg   if (dir1 >= 0x50) {
18971d7fec4Smrg      switch (dir0) {
19071d7fec4Smrg      case 0:
19171d7fec4Smrg      case 2:
19271d7fec4Smrg	 return 133;
19371d7fec4Smrg
19471d7fec4Smrg      case 5:
19571d7fec4Smrg	 return 166;
19671d7fec4Smrg      case 3:
19771d7fec4Smrg	 return 200;
19871d7fec4Smrg      case 6:
19971d7fec4Smrg	 return 233;
20071d7fec4Smrg      case 7:
20171d7fec4Smrg	 return 266;
20271d7fec4Smrg      case 4:
20371d7fec4Smrg	 return 300;
20471d7fec4Smrg      case 1:
20571d7fec4Smrg	 return 333;
20671d7fec4Smrg      default:
20771d7fec4Smrg	 return (0);
20871d7fec4Smrg      }
20971d7fec4Smrg   } else {
21071d7fec4Smrg      switch (dir0) {
21171d7fec4Smrg      case 0:
21271d7fec4Smrg      case 2:
21371d7fec4Smrg	 return 133;
21471d7fec4Smrg
21571d7fec4Smrg      case 7:
21671d7fec4Smrg	 return 166;
21771d7fec4Smrg
21871d7fec4Smrg      case 1:
21971d7fec4Smrg      case 3:
22071d7fec4Smrg	 return 200;
22171d7fec4Smrg
22271d7fec4Smrg      case 4:
22371d7fec4Smrg      case 6:
22471d7fec4Smrg	 return 233;
22571d7fec4Smrg
22671d7fec4Smrg      case 5:
22771d7fec4Smrg	 return 266;
22871d7fec4Smrg      default:
22971d7fec4Smrg	 return (0);
23071d7fec4Smrg      }
23171d7fec4Smrg   }
23271d7fec4Smrg   return (0);
23371d7fec4Smrg}
23471d7fec4Smrg
23571d7fec4Smrg/*-----------------------------------------------------------------------------
23671d7fec4Smrg * gfx_get_cpu_register_base
23771d7fec4Smrg *
23871d7fec4Smrg * This routine returns the base address for graphics registers.
23971d7fec4Smrg *-----------------------------------------------------------------------------
24071d7fec4Smrg */
24171d7fec4Smrg#if GFX_INIT_DYNAMIC
24271d7fec4Smrgunsigned long
24371d7fec4Smrggu1_get_cpu_register_base(void)
24471d7fec4Smrg#else
24571d7fec4Smrgunsigned long
24671d7fec4Smrggfx_get_cpu_register_base(void)
24771d7fec4Smrg#endif
24871d7fec4Smrg{
24971d7fec4Smrg   unsigned long base;
25071d7fec4Smrg
25171d7fec4Smrg   base = (unsigned long)gfx_gxm_config_read(GXM_CONFIG_GCR);
25271d7fec4Smrg   base = (base & 0x03) << 30;
25371d7fec4Smrg   return (base);
25471d7fec4Smrg}
25571d7fec4Smrg
25671d7fec4Smrg/*-----------------------------------------------------------------------------
25771d7fec4Smrg * gfx_get_frame_buffer_base
25871d7fec4Smrg *
25971d7fec4Smrg * This routine returns the base address for graphics memory.  This is an
26071d7fec4Smrg * offset of 0x00800000 from the base address specified in the GCR register.
26171d7fec4Smrg *
26271d7fec4Smrg * The function returns zero if the GCR indicates the graphics subsystem
26371d7fec4Smrg * is disabled.
26471d7fec4Smrg *-----------------------------------------------------------------------------
26571d7fec4Smrg */
26671d7fec4Smrg#if GFX_INIT_DYNAMIC
26771d7fec4Smrgunsigned long
26871d7fec4Smrggu1_get_frame_buffer_base(void)
26971d7fec4Smrg#else
27071d7fec4Smrgunsigned long
27171d7fec4Smrggfx_get_frame_buffer_base(void)
27271d7fec4Smrg#endif
27371d7fec4Smrg{
27471d7fec4Smrg   unsigned long base;
27571d7fec4Smrg
27671d7fec4Smrg   base = (unsigned long)gfx_gxm_config_read(GXM_CONFIG_GCR);
27771d7fec4Smrg   base = (base & 0x03) << 30;
27871d7fec4Smrg   if (base)
27971d7fec4Smrg      base |= 0x00800000;
28071d7fec4Smrg   return (base);
28171d7fec4Smrg}
28271d7fec4Smrg
28371d7fec4Smrg/*-----------------------------------------------------------------------------
28471d7fec4Smrg * gfx_get_frame_buffer_size
28571d7fec4Smrg *
28671d7fec4Smrg * This routine returns the total size of graphics memory, in bytes.
28771d7fec4Smrg *
28871d7fec4Smrg * Currently this routine is hardcoded to return 2 Meg.
28971d7fec4Smrg *-----------------------------------------------------------------------------
29071d7fec4Smrg */
29171d7fec4Smrg#if GFX_INIT_DYNAMIC
29271d7fec4Smrgunsigned long
29371d7fec4Smrggu1_get_frame_buffer_size(void)
29471d7fec4Smrg#else
29571d7fec4Smrgunsigned long
29671d7fec4Smrggfx_get_frame_buffer_size(void)
29771d7fec4Smrg#endif
29871d7fec4Smrg{
29971d7fec4Smrg#if FB4MB
30071d7fec4Smrg   return (0x00400000);
30171d7fec4Smrg#else
30271d7fec4Smrg   return (0x00200000);
30371d7fec4Smrg#endif
30471d7fec4Smrg}
30571d7fec4Smrg
30671d7fec4Smrg/*-----------------------------------------------------------------------------
30771d7fec4Smrg * gfx_get_vid_register_base
30871d7fec4Smrg *
30971d7fec4Smrg * This routine returns the base address for the video hardware.  It assumes
31071d7fec4Smrg * an offset of 0x00010000 from the base address specified by the GCR.
31171d7fec4Smrg *
31271d7fec4Smrg * The function returns zero if the GCR indicates the graphics subsystem
31371d7fec4Smrg * is disabled.
31471d7fec4Smrg *-----------------------------------------------------------------------------
31571d7fec4Smrg */
31671d7fec4Smrg#if GFX_INIT_DYNAMIC
31771d7fec4Smrgunsigned long
31871d7fec4Smrggu1_get_vid_register_base(void)
31971d7fec4Smrg#else
32071d7fec4Smrgunsigned long
32171d7fec4Smrggfx_get_vid_register_base(void)
32271d7fec4Smrg#endif
32371d7fec4Smrg{
32471d7fec4Smrg   unsigned long base;
32571d7fec4Smrg
32671d7fec4Smrg   base = (unsigned long)gfx_gxm_config_read(GXM_CONFIG_GCR);
32771d7fec4Smrg   base = (base & 0x03) << 30;
32871d7fec4Smrg   if (base)
32971d7fec4Smrg      base |= 0x00010000;
33071d7fec4Smrg   return (base);
33171d7fec4Smrg}
33271d7fec4Smrg
33371d7fec4Smrg/*-----------------------------------------------------------------------------
33471d7fec4Smrg * gfx_get_vip_register_base
33571d7fec4Smrg *
33671d7fec4Smrg * This routine returns the base address for the VIP hardware.  This is
33771d7fec4Smrg * only applicable to the SC1200, for which this routine assumes an offset
33871d7fec4Smrg * of 0x00015000 from the base address specified by the GCR.
33971d7fec4Smrg *
34071d7fec4Smrg * The function returns zero if the GCR indicates the graphics subsystem
34171d7fec4Smrg * is disabled.
34271d7fec4Smrg *-----------------------------------------------------------------------------
34371d7fec4Smrg */
34471d7fec4Smrg#if GFX_INIT_DYNAMIC
34571d7fec4Smrgunsigned long
34671d7fec4Smrggu1_get_vip_register_base(void)
34771d7fec4Smrg#else
34871d7fec4Smrgunsigned long
34971d7fec4Smrggfx_get_vip_register_base(void)
35071d7fec4Smrg#endif
35171d7fec4Smrg{
35271d7fec4Smrg   unsigned long base = 0;
35371d7fec4Smrg
35471d7fec4Smrg   if ((gfx_cpu_version & 0xFF) == GFX_CPU_SC1200) {
35571d7fec4Smrg      base = (unsigned long)gfx_gxm_config_read(GXM_CONFIG_GCR);
35671d7fec4Smrg      base = (base & 0x03) << 30;
35771d7fec4Smrg      if (base)
35871d7fec4Smrg	 base |= 0x00015000;
35971d7fec4Smrg   }
36071d7fec4Smrg   return (base);
36171d7fec4Smrg}
36271d7fec4Smrg
36371d7fec4Smrg/* END OF FILE */
364