drac9210.c revision f29dbc25
1/* Copyright (c) 2005 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/*
27 * File Contents:   This file contains the panel library files to the
28 *                  platforms with 9210, and 9211 support.
29 *
30 * SubModule:       Geode FlatPanel library
31 * */
32
33#include "drac9210.h"
34
35#define	CS9210			0x40   /* Chip select pin       */
36
37/* 9210 on Draco */
38#define CLOCK9210		0x04   /* Clock pin             */
39#define	DATAIN9210		0x20   /* Data from 9210        */
40#define	DATAOUT9210		0x80   /* Data to 9210          */
41
42static void DracoWriteData(unsigned char data);
43static void DracoReadData(unsigned char *data);
44static void Draco9210GpioInit();
45static void Draco9210SetCS(void);
46static unsigned char Draco9210ReadReg(unsigned char index);
47static void Draco9210WriteReg(unsigned char index, unsigned char data);
48static void Draco9210ClearCS(void);
49static void Draco9210SetDataOut(void);
50static void Draco9210ClearDataOut(void);
51static unsigned char Draco9210ReadDataIn(void);
52static void Draco9210ToggleClock(void);
53
54void
55Draco9210Init(Pnl_PanelStat * pstat)
56{
57    unsigned char panelvalues[] = {
58        0x2, 0x80,
59        0x2, 0x24,
60        0x03, 0x00,
61        0xc0, 0x00,
62        0xc1, 0x00,
63        0xc2, 0x00,
64        0xc3, 0x00,
65        0xc4, 0x00,
66        0xc5, 0x01,
67        0xc6, 0xff,
68        0xc7, 0xff,
69        0xc8, 0x3,
70        0xc9, 0xfe,
71        0xca, 0x0,
72        0xcb, 0x3f,
73        0xcc, 0xc,
74        0xcd, 0x1,
75        0xce, 0xff,
76        0xcf, 0xc1,
77        0xd0, 0x0,
78        0xd1, 0x7e,
79        0xd2, 0x3,
80        0xd3, 0xfe,
81        0xd4, 0x3,
82        0xd5, 0x81,
83        0xd6, 0xfc,
84        0xd7, 0x3f,
85        0xd8, 0x14,
86        0xd9, 0x1e,
87        0xda, 0x0f,
88        0xdb, 0xc7,
89        0xdc, 0x29,
90        0xdd, 0xe1,
91        0xde, 0xf1,
92        0xdf, 0xf9,
93        0xe0, 0x2,
94        0xe1, 0xe,
95        0xe2, 0x1e,
96        0xe3, 0x3e,
97        0xe4, 0x04,
98        0xe5, 0x71,
99        0xe6, 0xe3,
100        0xe7, 0xcf,
101        0xe8, 0x1,
102        0xe9, 0x86,
103        0xea, 0x3c,
104        0xeb, 0xf3,
105        0xec, 0xa,
106        0xed, 0x39,
107        0xee, 0xc7,
108        0xef, 0x3d,
109
110        0xf0, 0x14,
111        0xf1, 0xc6,
112        0xf2, 0x39,
113        0xf3, 0xce,
114        0xf4, 0x3,
115        0xf5, 0x19,
116        0xf6, 0xce,
117        0xf7, 0x77,
118        0xf8, 0x0,
119        0xf9, 0x66,
120        0xfa, 0x33,
121        0xfb, 0xbb,
122        0xfc, 0x2d,
123        0xfd, 0x99,
124        0xfe, 0xdd,
125        0xff, 0xdd,
126
127        0x3, 0x1,
128        0xc0, 0x2,
129        0xc1, 0x22,
130        0xc2, 0x66,
131        0xc3, 0x66,
132        0xc4, 0x0,
133        0xc5, 0xcd,
134        0xc6, 0x99,
135        0xc7, 0xbb,
136        0xc8, 0x5,
137        0xc9, 0x32,
138        0xca, 0x66,
139        0xcb, 0xdd,
140        0xcc, 0x1a,
141        0xcd, 0x4d,
142        0xce, 0x9b,
143        0xcf, 0x6f,
144        0xd0, 0x0,
145        0xd1, 0x92,
146        0xd2, 0x6d,
147        0xd3, 0xb6,
148        0xd4, 0x5,
149        0xd5, 0x25,
150        0xd6, 0xb6,
151        0xd7, 0xdb,
152        0xd8, 0x2,
153        0xd9, 0x5a,
154        0xda, 0x4b,
155        0xdb, 0x6d,
156        0xdc, 0x29,
157        0xdd, 0xa5,
158        0xde, 0xb5,
159        0xdf, 0xb7,
160        0xe0, 0x4,
161        0xe1, 0x4a,
162        0xe2, 0x5a,
163        0xe3, 0xda,
164        0xe4, 0x12,
165        0xe5, 0x95,
166        0xe6, 0xad,
167        0xe7, 0x6f,
168        0xe8, 0x1,
169        0xe9, 0x2a,
170        0xea, 0x56,
171        0xeb, 0xb5,
172        0xec, 0xe,
173        0xed, 0x55,
174        0xee, 0xab,
175        0xef, 0x5f,
176        0xf0, 0x0,
177        0xf1, 0xaa,
178        0xf2, 0x55,
179        0xf3, 0xea,
180        0xf4, 0x1,
181        0xf5, 0x55,
182        0xf6, 0xaa,
183        0xf7, 0xbf,
184        0xf8, 0x6,
185        0xf9, 0xaa,
186        0xfa, 0x55,
187        0xfb, 0x55,
188        0xfc, 0x39,
189        0xfd, 0x55,
190        0xfe, 0xff,
191        0xff, 0xff,
192
193        0x3, 0x2,
194        0xc0, 0x0,
195        0xc1, 0x0,
196        0xc2, 0xaa,
197        0xc3, 0xaa,
198        0xc4, 0x6,
199        0xc5, 0xab,
200        0xc6, 0x55,
201        0xc7, 0x55,
202        0xc8, 0x01,
203        0xc9, 0x54,
204        0xca, 0xaa,
205        0xcb, 0xbf,
206        0xcc, 0x8,
207        0xcd, 0xab,
208        0xce, 0x55,
209        0xcf, 0xeb,
210        0xd0, 0x6,
211        0xd1, 0x54,
212        0xd2, 0xab,
213        0xd3, 0x5e,
214        0xd4, 0x1,
215        0xd5, 0x2b,
216        0xd6, 0x56,
217        0xd7, 0xb5,
218        0xd8, 0x12,
219        0xd9, 0x94,
220        0xda, 0xad,
221        0xdb, 0x6f,
222        0xdc, 0x2d,
223        0xdd, 0x4b,
224        0xde, 0x5b,
225        0xdf, 0xdb,
226        0xe0, 0x0,
227        0xe1, 0xa4,
228        0xe2, 0xb4,
229        0xe3, 0xb6,
230        0xe4, 0x2,
231        0xe5, 0x5b,
232        0xe6, 0x4b,
233        0xe7, 0x6d,
234        0xe8, 0x5,
235        0xe9, 0x24,
236        0xea, 0xb6,
237        0xeb, 0xdb,
238        0xec, 0x8,
239        0xed, 0x93,
240        0xee, 0x6d,
241        0xef, 0xb7,
242        0xf0, 0x12,
243        0xf1, 0x4c,
244        0xf2, 0x9b,
245        0xf3, 0x6e,
246        0xf4, 0x5,
247        0xf5, 0x33,
248        0xf6, 0x66,
249        0xf7, 0xdd,
250        0xf8, 0x0,
251        0xf9, 0xcc,
252        0xfa, 0x99,
253        0xfb, 0xbb,
254        0xfc, 0x2b,
255        0xfd, 0x33,
256        0xfe, 0x77,
257        0xff, 0x77,
258
259        0x3, 0x3,
260        0xc0, 0x4,
261        0xc1, 0x88,
262        0xc2, 0xcc,
263        0xc3, 0xcc,
264        0xc4, 0x0,
265        0xc5, 0x67,
266        0xc6, 0x33,
267        0xc7, 0xbb,
268        0xc8, 0x3,
269        0xc9, 0x18,
270        0xca, 0xce,
271        0xcb, 0x77,
272        0xcc, 0x1c,
273        0xcd, 0xc7,
274        0xce, 0x39,
275        0xcf, 0xcf,
276
277        0xd0, 0x2,
278        0xd1, 0x38,
279        0xd2, 0xc7,
280        0xd3, 0x3c,
281        0xd4, 0x1,
282        0xd5, 0x87,
283        0xd6, 0x3c,
284        0xd7, 0xf3,
285        0xd8, 0x4,
286        0xd9, 0x70,
287        0xda, 0xe3,
288        0xdb, 0xcf,
289        0xdc, 0x2b,
290        0xdd, 0xf,
291        0xde, 0x1f,
292        0xdf, 0x3f,
293        0xe0, 0x00,
294        0xe1, 0xe0,
295        0xe2, 0xf0,
296        0xe3, 0xf8,
297        0xe4, 0x14,
298        0xe5, 0x1f,
299        0xe6, 0xf,
300        0xe7, 0xc7,
301        0xe8, 0x3,
302        0xe9, 0x80,
303        0xea, 0xfc,
304        0xeb, 0x3f,
305        0xec, 0x8,
306        0xed, 0x7f,
307        0xee, 0x3,
308        0xef, 0xff,
309        0xf0, 0x4,
310        0xf1, 0x0,
311        0xf2, 0xff,
312        0xf3, 0xc0,
313        0xf4, 0x3,
314        0xf5, 0xff,
315        0xf6, 0x0,
316        0xf7, 0x3f,
317        0xf8, 0x0,
318        0xf9, 0x0,
319        0xfa, 0xff,
320        0xfb, 0xff,
321        0xfc, 0x3f,
322        0xfd, 0xff,
323        0xfe, 0xff,
324        0xff, 0xff,
325        0x3, 0x4,
326
327        /* Setup the Diter to Pattern33 */
328        0x80, 0xdd,
329        0x81, 0xdd,
330        0x82, 0x33,
331        0x83, 0x33,
332        0x84, 0xdd,
333        0x85, 0xdd,
334        0x86, 0x33,
335        0x87, 0x33,
336        0x88, 0x33,
337        0x89, 0x33,
338        0x8a, 0x77,
339        0x8b, 0x77,
340        0x8c, 0x33,
341        0x8d, 0x33,
342        0x8e, 0x77,
343        0x8f, 0x77,
344        0x90, 0xdd,
345        0x91, 0xdd,
346        0x92, 0x33,
347        0x93, 0x33,
348        0x94, 0xdd,
349        0x95, 0xdd,
350        0x96, 0x33,
351        0x97, 0x33,
352        0x98, 0x33,
353        0x99, 0x33,
354        0x9a, 0x77,
355        0x9b, 0x77,
356        0x9c, 0x33,
357        0x9d, 0x33,
358        0x9e, 0x77,
359        0x9f, 0x77,
360
361        0x4, 0x20,
362        0x5, 0x3,
363        0x6, 0x56,
364        0x7, 0x2,
365        0x8, 0x1c,
366        0x9, 0x0,
367        0xa, 0x26,
368        0xb, 0x0,
369        0xc, 0x15,
370        0xd, 0x4,
371        0xe, 0x50,
372        0xf, 0x4,
373        0x10, 0xfa,
374        0x11, 0x0,
375        0x12, 0xc8,
376        0x13, 0x0,
377        0x14, 0x31,
378        0x15, 0x23,
379        0x16, 0x0,
380
381        /* Enable DSTN panel */
382        0x2, 0x64
383    };
384    unsigned char index, data;
385    int i;
386
387    gfx_delay_milliseconds(100);
388    Draco9210GpioInit();
389    Draco9210SetCS();
390    Draco9210ToggleClock();
391    Draco9210ToggleClock();
392    Draco9210ToggleClock();
393    Draco9210ToggleClock();
394    Draco9210ClearCS();
395
396#if defined(_WIN32)                    /* For Windows   */
397    for (i = 0; i < 10; i++) {
398        _asm {
399        out 0ED h, al}
400    }
401
402#elif defined(linux)                   /* Linux                 */
403
404#endif
405
406    for (i = 0; i < 630; i += 2) {
407        index = panelvalues[i];
408        data = panelvalues[i + 1];
409        Draco9210WriteReg(index, data);
410    }
411
412}
413
414static void
415DracoWriteData(unsigned char data)
416{
417    int i;
418    unsigned char mask = 0x80, databit;
419
420    for (i = 0; i < 8; i++) {
421
422        databit = data & mask;
423        if (data & mask) {
424            Draco9210SetDataOut();
425        } else {
426            Draco9210ClearDataOut();
427        }
428        mask >>= 1;
429        Draco9210ToggleClock();
430    }
431}
432
433static void
434DracoReadData(unsigned char *data)
435{
436    int i;
437    unsigned char tmp = 0, readbit;
438
439    Draco9210ClearDataOut();
440    Draco9210ToggleClock();
441    for (i = 0; i < 7; i++) {
442        readbit = Draco9210ReadDataIn();
443        tmp |= (readbit & 0x1);
444        tmp <<= 1;
445        Draco9210ToggleClock();
446    }
447    readbit = Draco9210ReadDataIn();
448    tmp |= (readbit & 0x1);
449    *data = tmp;
450}
451
452#if defined(_WIN32)                    /* For Windows */
453
454void
455Draco9210GpioInit()
456{
457    _asm {
458    pushf
459            cli
460            mov dx, 0 CF8h
461            mov eax, CX55x0_ID + 090 h
462            out dx, eax
463            mov dx, 0 CFCh mov al, 0 CFh mov ah, 00 h out dx, ax popf}
464}
465
466void
467Draco9210SetCS()
468{
469    _asm {
470        pushf;
471        Point to PCI address register mov dx, 0 CF8h;
472        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
473        Point to PCI data register (CFCh)
474    mov dx, 0 CFCh
475            in ax, dx
476            and ah, 30 h
477            mov ah, c92DataReg
478            or ah, CS9210 mov c92DataReg, ah out dx, ax popf}
479}
480
481void
482Draco9210ClearCS()
483{
484    _asm {
485        pushf;
486        Point to PCI address register mov dx, 0 CF8h;
487        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
488        Point to PCI data register (CFCh)
489        mov dx, 0 CFCh;
490    Set CS LOW
491            in ax, dx
492            mov ah, c92DataReg
493            and ah, NOT CS9210 mov c92DataReg, ah out dx, ax popf}
494}
495
496void
497Draco9210SetDataOut()
498{
499    _asm {
500        pushf;
501        Point to PCI address register mov dx, 0 CF8h;
502        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
503        Point to PCI data register (CFCh)
504        mov dx, 0 CFCh;
505    Set DATA HIGH
506            in ax, dx
507            mov ah, c92DataReg
508            or ah, DATAOUT9210 mov c92DataReg, ah out dx, ax popf}
509}
510
511void
512Draco9210ClearDataOut()
513{
514    _asm {
515        pushf;
516        Point to PCI address register
517            mov dx, 0 CF8h mov eax, CX55x0_ID + 090 h;
518        ;
519        55 XX GPIO data register out dx, eax;
520        Point to PCI data register (CFCh)
521        mov dx, 0 CFCh;
522    Set Data LOW
523            in ax, dx
524            mov ah, c92DataReg
525            and ah, NOT DATAOUT9210 mov c92DataReg, ah out dx, ax popf}
526}
527
528unsigned char
529Draco9210ReadDataIn()
530{
531    unsigned char readdata;
532
533    _asm {
534        pushf;
535        Point to PCI address register mov dx, 0 CF8h;
536        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
537        Point to PCI data register (CFCh)
538        mov dx, 0F Ch in ax, dx;
539        Preserve just Data IN bit and ah, DATAIN9210 mov al, ah cmp al, 0;
540        Is it LOW ? je readDataLow;
541    must be HIGH mov al, 1 readDataLow:mov readdata, al popf}
542    return (readdata);
543}
544
545void
546Draco9210ToggleClock()
547{
548    _asm {
549        pushf;
550        Point to PCI address register mov dx, 0 CF8h;
551        55 XX GPIO data register mov eax, CX55x0_ID + 090 h;
552        Point to PCI data register (CFCh)
553        out dx, eax mov dx, 0 CFCh;
554        SET CLOCK in ax, dx mov ah, c92DataReg or ah, CLOCK9210 mov c92DataReg, ah out dx, ax out 0ED h, al     /* IOPAUSE      */
555           ;
556        Point to PCI address register mov dx, 0 CF8h;
557        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
558        Point to PCI data register (CFCh)
559        mov dx, 0 CFCh;
560
561        ;
562    CLEAR CLOCK
563            in ax, dx
564            mov ah, c92DataReg
565            and ah, NOT CLOCK9210 mov c92DataReg, ah out dx, ax popf}
566}
567
568#elif defined(linux)                   /* Linux         */
569
570void
571Draco9210GpioInit()
572{
573}
574void
575Draco9210SetCS()
576{
577}
578void
579Draco9210ClearCS()
580{
581}
582void
583Draco9210SetDataOut()
584{
585}
586void
587Draco9210ClearDataOut()
588{
589}
590unsigned char
591Draco9210ReadDataIn()
592{
593}
594void
595Draco9210ToggleClock()
596{
597}
598
599#endif
600
601unsigned char
602Draco9210ReadReg(unsigned char index)
603{
604    unsigned char data;
605
606    Draco9210SetCS();
607    Draco9210ToggleClock();
608    Draco9210SetDataOut();
609    Draco9210ToggleClock();
610    Draco9210ClearDataOut();
611    Draco9210ToggleClock();
612    Draco9210ClearDataOut();
613    Draco9210ToggleClock();
614    Draco9210ClearDataOut();
615    Draco9210ToggleClock();
616
617    DracoWriteData(index);
618    DracoReadData(&data);
619
620    return (data);
621}
622
623void
624Draco9210WriteReg(unsigned char index, unsigned char data)
625{
626
627    Draco9210SetCS();
628    Draco9210ToggleClock();
629
630    Draco9210SetDataOut();
631    Draco9210ToggleClock();
632
633    Draco9210ClearDataOut();
634    Draco9210ToggleClock();
635
636    Draco9210ClearDataOut();
637    Draco9210ToggleClock();
638
639    Draco9210SetDataOut();
640    Draco9210ToggleClock();
641
642    DracoWriteData(index);
643    DracoWriteData(data);
644
645    Draco9210ClearDataOut();
646    Draco9210ToggleClock();
647
648    Draco9210ClearCS();
649    Draco9210ToggleClock();
650    Draco9210ToggleClock();
651
652}
653