summaryrefslogtreecommitdiff
path: root/Source/DirectFB/gfxdrivers/mach64/mmio.h
blob: c8aed850d627804383b52733d194a8658a3e82df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   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.
*/


#ifndef ___MACH64_MMIO_H__
#define ___MACH64_MMIO_H__

#include <dfb_types.h>

#include "mach64.h"

static inline void
mach64_out8( volatile u8 *mmioaddr, u32 reg, u8 value )
{
     *((volatile u8*)(mmioaddr+reg)) = value;
}

static inline u8
mach64_in8( volatile u8 *mmioaddr, u32 reg )
{
     return *((volatile u8*)(mmioaddr+reg));
}

static inline void
mach64_out32( volatile u8 *mmioaddr, u32 reg, u32 value )
{
#ifdef __powerpc__
     if (reg >= 0x400)
          asm volatile("stwbrx %0,%1,%2;eieio" : : "r"(value), "b"(reg-0x800),
                              "r"(mmioaddr) : "memory");
     else
          asm volatile("stwbrx %0,%1,%2;eieio" : : "r"(value), "b"(reg),
                              "r"(mmioaddr) : "memory");
#else
     if (reg >= 0x400)
          *((volatile u32*)(mmioaddr+reg-0x800)) = value;
     else
          *((volatile u32*)(mmioaddr+reg)) = value;
#endif
}

static inline u32
mach64_in32( volatile u8 *mmioaddr, u32 reg )
{
#ifdef __powerpc__
     u32 value;

     if (reg >= 0x400)
          asm volatile("lwbrx %0,%1,%2;eieio" : "=r"(value) : "b"(reg-0x800), "r"(mmioaddr));
     else
          asm volatile("lwbrx %0,%1,%2;eieio" : "=r"(value) : "b"(reg), "r"(mmioaddr));

     return value;
#else
     if (reg >= 0x400)
          return *((volatile u32*)(mmioaddr+reg-0x800));
     else
          return *((volatile u32*)(mmioaddr+reg));
#endif
}

static const u32 lt_lcd_regs[] = {
     CONFIG_PANEL_LT,
     LCD_GEN_CTRL_LT,
     DSTN_CONTROL_LT,
     HFB_PITCH_ADDR_LT,
     HORZ_STRETCHING_LT,
     VERT_STRETCHING_LT,
     0, /* EXT_VERT_STRETCH */
     LT_GIO_LT,
     POWER_MANAGEMENT_LT
};

#if 0
static inline void
mach64_in_lcd( Mach64DeviceData *mdev,
               volatile u8      *mmioaddr, u8 reg, u32 value )
{
     if (mdev->chip == CHIP_3D_RAGE_LT) {
          mach64_out32( mmioaddr, lt_lcd_regs[reg], value );
     } else if (mdev->chip >= CHIP_3D_RAGE_LT_PRO) {
          mach64_out8( mmioaddr, LCD_INDEX, reg );
          mach64_out32( mmioaddr, LCD_DATA, value );
     }
}
#endif

static inline u32
mach64_in_lcd( Mach64DeviceData *mdev,
               volatile u8      *mmioaddr, u8 reg )
{
     if (mdev->chip == CHIP_3D_RAGE_LT) {
          return mach64_in32( mmioaddr, lt_lcd_regs[reg] );
     } else if (mdev->chip >= CHIP_3D_RAGE_LT_PRO) {
          mach64_out8( mmioaddr, LCD_INDEX, reg );
          return mach64_in32( mmioaddr, LCD_DATA );
     } else {
          return 0;
     }
}

#if 0
static inline void
mach64_out_pll( volatile u8 *mmioaddr, u8 reg, u8 value )
{
     mach64_out8( mmioaddr, CLOCK_CNTL1, (reg << 2) | PLL_WR_EN );
     mach64_out8( mmioaddr, CLOCK_CNTL2, value );
}
#endif

static inline u8
mach64_in_pll( volatile u8 *mmioaddr, u8 reg )
{
     mach64_out8( mmioaddr, CLOCK_CNTL1, reg << 2 );
     return mach64_in8( mmioaddr, CLOCK_CNTL2 );
}

static inline void mach64_waitidle( Mach64DriverData *mdrv,
                                    Mach64DeviceData *mdev )
{
     int timeout = 1000000;

     while (timeout--) {
          if ((mach64_in32( mdrv->mmio_base, FIFO_STAT ) & 0x0000FFFF) == 0)
               break;

          mdev->idle_waitcycles++;
     }

     timeout = 1000000;

     while (timeout--) {
          if ((mach64_in32( mdrv->mmio_base, GUI_STAT ) & GUI_ACTIVE) == 0)
               break;

          mdev->idle_waitcycles++;
     }

     mdev->fifo_space = 16;
}

static inline void mach64_waitfifo( Mach64DriverData *mdrv,
                                    Mach64DeviceData *mdev,
                                    unsigned int requested_fifo_space )
{
     u32 fifo_stat;
     int timeout = 1000000;

     mdev->waitfifo_sum += requested_fifo_space;
     mdev->waitfifo_calls++;

     if (mdev->fifo_space < requested_fifo_space) {
          while (timeout--) {
               mdev->fifo_waitcycles++;

               fifo_stat = mach64_in32( mdrv->mmio_base, FIFO_STAT ) & 0x0000FFFF;
               mdev->fifo_space = 16;
               while (fifo_stat) {
                    mdev->fifo_space--;
                    fifo_stat >>= 1;
               }

               if (mdev->fifo_space >= requested_fifo_space)
                    break;
          }
     }
     else {
          mdev->fifo_cache_hits++;
     }
     mdev->fifo_space -= requested_fifo_space;
}

#endif