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
|
/* Copyright (c) 2006 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Neither the name of the Advanced Micro Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
* */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* Includes that are used by all drivers */
#include <xf86.h>
#include <xf86_OSproc.h>
#include <xf86_ansic.h>
#include <xf86_libc.h>
#include <xf86Resources.h>
#include <xf86_ansic.h>
#include <compiler.h>
#include "amd.h"
/* OLPC board revision */
#define REV_TESTA 0
#define REV_TESTB 1
/* Values in the embedded controller */
#define TESTA_REVISION 0x09
#define EC_VER_CMD 0x09
/* This is a special color map used for video in the GX engine */
/* on a rev-B DCON, this should be adjusted */
extern unsigned long gfx_gamma_ram_redcloud[];
/* Get the current board revision in a roundabout way by querying the
embedded controller
*/
static int
eccmd(ScrnInfoPtr pScrni, unsigned char cmd)
{
unsigned char ret;
int i;
ret = inb(0x6c);
if (ret & 1)
ret = inb(0x68);
/* Write the command */
outb(0x6C, cmd);
/* Wait for the 2 response */
for (i = 0; i < 1000; i++) {
ret = inb(0x6C);
if ((ret & 3) == 1)
break;
}
if (i == 100) {
xf86DrvMsg(pScrni->scrnIndex, X_ERROR,
"Error waiting for the EC command (%x)\n", ret);
ret = -1;
goto eread;
}
/* get the response */
ret = inb(0x68);
eread:
/* Clear the "ownership flag" */
outb(0x6C, 0xFF);
return ret;
}
static int
boardrev(ScrnInfoPtr pScrni)
{
int i, ret;
ret = eccmd(pScrni, 0x09);
if (ret == -1)
return -1;
return ret == TESTA_REVISION ? REV_TESTA : REV_TESTB;
}
#define RTC_BASE_PORT 0x70
#define RTC_PORT(x) (RTC_BASE_PORT + (x))
static inline char
cmos_read(unsigned char addr)
{
outb(RTC_PORT(0), addr);
return inb(RTC_PORT(1));
}
static inline void
cmos_write(unsigned char val, unsigned char addr)
{
outb(RTC_PORT(0), addr);
outb(RTC_PORT(1), val);
}
static int
dcon_avail(void)
{
return cmos_read(440 / 8) & 1;
}
Bool
gx_dcon_init(ScrnInfoPtr pScrni)
{
GeodeRec *pGeode = GEODEPTR(pScrni);
int rev = boardrev(pScrni);
int i;
if (rev == -1) {
xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT,
"This is not an OLPC board\n");
return FALSE;
}
if (dcon_avail() == 0) {
xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "No DCON is present\n");
return FALSE;
}
xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "OLPC board revision %s\n",
rev == REV_TESTB ? "testB" : "testA");
xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "DCON detected.\n");
/* Panel size setup */
pGeode->PanelX = DCON_DEFAULT_XRES;
pGeode->PanelY = DCON_DEFAULT_YRES;
/* FIXME: Mode setup should go here */
/* FIXME: Controller setup should go here */
/* Update the Xv map on a rev-b board */
if (rev == REV_TESTB) {
for (i = 0; i < 256; i++) {
unsigned char r, g, b;
r = (gfx_gamma_ram_redcloud[i] >> 16) & 0xFF;
g = (gfx_gamma_ram_redcloud[i] >> 8) & 0xFF;
b = gfx_gamma_ram_redcloud[i] & 0xFF;
gfx_gamma_ram_redcloud[i] =
((r >> 2) << 16) | ((g >> 1) << 8) | (b >> 2);
}
}
return TRUE;
}
|