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        }
426        else {
427            Draco9210ClearDataOut();
428        }
429        mask >>= 1;
430        Draco9210ToggleClock();
431    }
432}
433
434static void
435DracoReadData(unsigned char *data)
436{
437    int i;
438    unsigned char tmp = 0, readbit;
439
440    Draco9210ClearDataOut();
441    Draco9210ToggleClock();
442    for (i = 0; i < 7; i++) {
443        readbit = Draco9210ReadDataIn();
444        tmp |= (readbit & 0x1);
445        tmp <<= 1;
446        Draco9210ToggleClock();
447    }
448    readbit = Draco9210ReadDataIn();
449    tmp |= (readbit & 0x1);
450    *data = tmp;
451}
452
453#if defined(_WIN32)             /* For Windows */
454
455void
456Draco9210GpioInit()
457{
458    _asm {
459    pushf
460            cli
461            mov dx, 0 CF8h
462            mov eax, CX55x0_ID + 090 h
463            out dx, eax
464            mov dx, 0 CFCh mov al, 0 CFh mov ah, 00 h out dx, ax popf}
465}
466
467void
468Draco9210SetCS()
469{
470    _asm {
471        pushf;
472        Point to PCI address register mov dx, 0 CF8h;
473        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
474        Point to PCI data register (CFCh)
475mov dx, 0 CFCh
476            in ax, dx
477            and ah, 30 h
478            mov ah, c92DataReg
479            or ah, CS9210 mov c92DataReg, ah out dx, ax popf}} void
480Draco9210ClearCS()
481{
482    _asm {
483        pushf;
484        Point to PCI address register mov dx, 0 CF8h;
485        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
486        Point to PCI data register (CFCh)
487        mov dx, 0 CFCh;
488Set CS LOW
489            in ax, dx
490            mov ah, c92DataReg
491            and ah, NOT CS9210 mov c92DataReg, ah out dx, ax popf}} void
492Draco9210SetDataOut()
493{
494    _asm {
495        pushf;
496        Point to PCI address register mov dx, 0 CF8h;
497        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
498        Point to PCI data register (CFCh)
499        mov dx, 0 CFCh;
500Set DATA HIGH
501            in ax, dx
502            mov ah, c92DataReg
503            or ah, DATAOUT9210 mov c92DataReg, ah out dx, ax popf}} void
504Draco9210ClearDataOut()
505{
506    _asm {
507        pushf;
508        Point to PCI address register
509        mov dx, 0 CF8h mov eax, CX55x0_ID + 090 h;
510
511        ;
512        55 XX GPIO data register out dx, eax;
513        Point to PCI data register (CFCh)
514        mov dx, 0 CFCh;
515Set Data LOW
516            in ax, dx
517            mov ah, c92DataReg
518            and ah, NOT DATAOUT9210 mov c92DataReg, ah out dx, ax popf}}
519    unsigned char
520Draco9210ReadDataIn()
521{
522    unsigned char readdata;
523
524    _asm {
525        pushf;
526        Point to PCI address register mov dx, 0 CF8h;
527        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
528        Point to PCI data register (CFCh)
529        mov dx, 0F Ch in ax, dx;
530        Preserve just Data IN bit and ah, DATAIN9210 mov al, ah cmp al, 0;
531        Is it LOW ? je readDataLow;
532    must be HIGH mov al, 1 readDataLow:mov readdata, al popf} return (readdata);
533}
534
535void
536Draco9210ToggleClock()
537{
538    _asm {
539        pushf;
540        Point to PCI address register mov dx, 0 CF8h;
541        55 XX GPIO data register mov eax, CX55x0_ID + 090 h;
542        Point to PCI data register (CFCh)
543        out dx, eax mov dx, 0 CFCh;
544        SET CLOCK in ax, dx mov ah, c92DataReg or ah, CLOCK9210 mov c92DataReg, ah out dx, ax out 0ED h, al     /* IOPAUSE      */
545        ;
546        Point to PCI address register mov dx, 0 CF8h;
547        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
548        Point to PCI data register (CFCh)
549        mov dx, 0 CFCh;
550
551        ;
552CLEAR CLOCK
553            in ax, dx
554            mov ah, c92DataReg
555            and ah, NOT CLOCK9210 mov c92DataReg, ah out dx, ax popf}}
556#elif defined(linux)            /* Linux         */
557
558void
559Draco9210GpioInit()
560{
561}
562
563void
564Draco9210SetCS()
565{
566}
567
568void
569Draco9210ClearCS()
570{
571}
572
573void
574Draco9210SetDataOut()
575{
576}
577
578void
579Draco9210ClearDataOut()
580{
581}
582
583unsigned char
584Draco9210ReadDataIn()
585{
586}
587
588void
589Draco9210ToggleClock()
590{
591}
592
593#endif
594
595unsigned char
596Draco9210ReadReg(unsigned char index)
597{
598    unsigned char data;
599
600    Draco9210SetCS();
601    Draco9210ToggleClock();
602    Draco9210SetDataOut();
603    Draco9210ToggleClock();
604    Draco9210ClearDataOut();
605    Draco9210ToggleClock();
606    Draco9210ClearDataOut();
607    Draco9210ToggleClock();
608    Draco9210ClearDataOut();
609    Draco9210ToggleClock();
610
611    DracoWriteData(index);
612    DracoReadData(&data);
613
614    return (data);
615}
616
617void
618Draco9210WriteReg(unsigned char index, unsigned char data)
619{
620
621    Draco9210SetCS();
622    Draco9210ToggleClock();
623
624    Draco9210SetDataOut();
625    Draco9210ToggleClock();
626
627    Draco9210ClearDataOut();
628    Draco9210ToggleClock();
629
630    Draco9210ClearDataOut();
631    Draco9210ToggleClock();
632
633    Draco9210SetDataOut();
634    Draco9210ToggleClock();
635
636    DracoWriteData(index);
637    DracoWriteData(data);
638
639    Draco9210ClearDataOut();
640    Draco9210ToggleClock();
641
642    Draco9210ClearCS();
643    Draco9210ToggleClock();
644    Draco9210ToggleClock();
645
646}
647