summaryrefslogtreecommitdiff
path: root/src/panel/drac9210.c
blob: 4eb0a98e8cb83a61e4cba73d0b08b6b7d6b8b412 (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
/* Copyright (c) 2005 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.
 * */

/* 
 * File Contents:   This file contains the panel library files to the 
 *                  platforms with 9210, and 9211 support.
 *                	
 * SubModule:       Geode FlatPanel library
 * */

#include "drac9210.h"

#define	CS9210			0x40    /* Chip select pin       */

/* 9210 on Draco */
#define CLOCK9210		0x04    /* Clock pin             */
#define	DATAIN9210		0x20    /* Data from 9210        */
#define	DATAOUT9210		0x80    /* Data to 9210          */

static void DracoWriteData(unsigned char data);
static void DracoReadData(unsigned char *data);
static void Draco9210GpioInit();
static void Draco9210SetCS(void);
static unsigned char Draco9210ReadReg(unsigned char index);
static void Draco9210WriteReg(unsigned char index, unsigned char data);
static void Draco9210ClearCS(void);
static void Draco9210SetDataOut(void);
static void Draco9210ClearDataOut(void);
static unsigned char Draco9210ReadDataIn(void);
static void Draco9210ToggleClock(void);

void
Draco9210Init(Pnl_PanelStat * pstat)
{
    unsigned char panelvalues[] = {
        0x2, 0x80,
        0x2, 0x24,
        0x03, 0x00,
        0xc0, 0x00,
        0xc1, 0x00,
        0xc2, 0x00,
        0xc3, 0x00,
        0xc4, 0x00,
        0xc5, 0x01,
        0xc6, 0xff,
        0xc7, 0xff,
        0xc8, 0x3,
        0xc9, 0xfe,
        0xca, 0x0,
        0xcb, 0x3f,
        0xcc, 0xc,
        0xcd, 0x1,
        0xce, 0xff,
        0xcf, 0xc1,
        0xd0, 0x0,
        0xd1, 0x7e,
        0xd2, 0x3,
        0xd3, 0xfe,
        0xd4, 0x3,
        0xd5, 0x81,
        0xd6, 0xfc,
        0xd7, 0x3f,
        0xd8, 0x14,
        0xd9, 0x1e,
        0xda, 0x0f,
        0xdb, 0xc7,
        0xdc, 0x29,
        0xdd, 0xe1,
        0xde, 0xf1,
        0xdf, 0xf9,
        0xe0, 0x2,
        0xe1, 0xe,
        0xe2, 0x1e,
        0xe3, 0x3e,
        0xe4, 0x04,
        0xe5, 0x71,
        0xe6, 0xe3,
        0xe7, 0xcf,
        0xe8, 0x1,
        0xe9, 0x86,
        0xea, 0x3c,
        0xeb, 0xf3,
        0xec, 0xa,
        0xed, 0x39,
        0xee, 0xc7,
        0xef, 0x3d,

        0xf0, 0x14,
        0xf1, 0xc6,
        0xf2, 0x39,
        0xf3, 0xce,
        0xf4, 0x3,
        0xf5, 0x19,
        0xf6, 0xce,
        0xf7, 0x77,
        0xf8, 0x0,
        0xf9, 0x66,
        0xfa, 0x33,
        0xfb, 0xbb,
        0xfc, 0x2d,
        0xfd, 0x99,
        0xfe, 0xdd,
        0xff, 0xdd,

        0x3, 0x1,
        0xc0, 0x2,
        0xc1, 0x22,
        0xc2, 0x66,
        0xc3, 0x66,
        0xc4, 0x0,
        0xc5, 0xcd,
        0xc6, 0x99,
        0xc7, 0xbb,
        0xc8, 0x5,
        0xc9, 0x32,
        0xca, 0x66,
        0xcb, 0xdd,
        0xcc, 0x1a,
        0xcd, 0x4d,
        0xce, 0x9b,
        0xcf, 0x6f,
        0xd0, 0x0,
        0xd1, 0x92,
        0xd2, 0x6d,
        0xd3, 0xb6,
        0xd4, 0x5,
        0xd5, 0x25,
        0xd6, 0xb6,
        0xd7, 0xdb,
        0xd8, 0x2,
        0xd9, 0x5a,
        0xda, 0x4b,
        0xdb, 0x6d,
        0xdc, 0x29,
        0xdd, 0xa5,
        0xde, 0xb5,
        0xdf, 0xb7,
        0xe0, 0x4,
        0xe1, 0x4a,
        0xe2, 0x5a,
        0xe3, 0xda,
        0xe4, 0x12,
        0xe5, 0x95,
        0xe6, 0xad,
        0xe7, 0x6f,
        0xe8, 0x1,
        0xe9, 0x2a,
        0xea, 0x56,
        0xeb, 0xb5,
        0xec, 0xe,
        0xed, 0x55,
        0xee, 0xab,
        0xef, 0x5f,
        0xf0, 0x0,
        0xf1, 0xaa,
        0xf2, 0x55,
        0xf3, 0xea,
        0xf4, 0x1,
        0xf5, 0x55,
        0xf6, 0xaa,
        0xf7, 0xbf,
        0xf8, 0x6,
        0xf9, 0xaa,
        0xfa, 0x55,
        0xfb, 0x55,
        0xfc, 0x39,
        0xfd, 0x55,
        0xfe, 0xff,
        0xff, 0xff,

        0x3, 0x2,
        0xc0, 0x0,
        0xc1, 0x0,
        0xc2, 0xaa,
        0xc3, 0xaa,
        0xc4, 0x6,
        0xc5, 0xab,
        0xc6, 0x55,
        0xc7, 0x55,
        0xc8, 0x01,
        0xc9, 0x54,
        0xca, 0xaa,
        0xcb, 0xbf,
        0xcc, 0x8,
        0xcd, 0xab,
        0xce, 0x55,
        0xcf, 0xeb,
        0xd0, 0x6,
        0xd1, 0x54,
        0xd2, 0xab,
        0xd3, 0x5e,
        0xd4, 0x1,
        0xd5, 0x2b,
        0xd6, 0x56,
        0xd7, 0xb5,
        0xd8, 0x12,
        0xd9, 0x94,
        0xda, 0xad,
        0xdb, 0x6f,
        0xdc, 0x2d,
        0xdd, 0x4b,
        0xde, 0x5b,
        0xdf, 0xdb,
        0xe0, 0x0,
        0xe1, 0xa4,
        0xe2, 0xb4,
        0xe3, 0xb6,
        0xe4, 0x2,
        0xe5, 0x5b,
        0xe6, 0x4b,
        0xe7, 0x6d,
        0xe8, 0x5,
        0xe9, 0x24,
        0xea, 0xb6,
        0xeb, 0xdb,
        0xec, 0x8,
        0xed, 0x93,
        0xee, 0x6d,
        0xef, 0xb7,
        0xf0, 0x12,
        0xf1, 0x4c,
        0xf2, 0x9b,
        0xf3, 0x6e,
        0xf4, 0x5,
        0xf5, 0x33,
        0xf6, 0x66,
        0xf7, 0xdd,
        0xf8, 0x0,
        0xf9, 0xcc,
        0xfa, 0x99,
        0xfb, 0xbb,
        0xfc, 0x2b,
        0xfd, 0x33,
        0xfe, 0x77,
        0xff, 0x77,

        0x3, 0x3,
        0xc0, 0x4,
        0xc1, 0x88,
        0xc2, 0xcc,
        0xc3, 0xcc,
        0xc4, 0x0,
        0xc5, 0x67,
        0xc6, 0x33,
        0xc7, 0xbb,
        0xc8, 0x3,
        0xc9, 0x18,
        0xca, 0xce,
        0xcb, 0x77,
        0xcc, 0x1c,
        0xcd, 0xc7,
        0xce, 0x39,
        0xcf, 0xcf,

        0xd0, 0x2,
        0xd1, 0x38,
        0xd2, 0xc7,
        0xd3, 0x3c,
        0xd4, 0x1,
        0xd5, 0x87,
        0xd6, 0x3c,
        0xd7, 0xf3,
        0xd8, 0x4,
        0xd9, 0x70,
        0xda, 0xe3,
        0xdb, 0xcf,
        0xdc, 0x2b,
        0xdd, 0xf,
        0xde, 0x1f,
        0xdf, 0x3f,
        0xe0, 0x00,
        0xe1, 0xe0,
        0xe2, 0xf0,
        0xe3, 0xf8,
        0xe4, 0x14,
        0xe5, 0x1f,
        0xe6, 0xf,
        0xe7, 0xc7,
        0xe8, 0x3,
        0xe9, 0x80,
        0xea, 0xfc,
        0xeb, 0x3f,
        0xec, 0x8,
        0xed, 0x7f,
        0xee, 0x3,
        0xef, 0xff,
        0xf0, 0x4,
        0xf1, 0x0,
        0xf2, 0xff,
        0xf3, 0xc0,
        0xf4, 0x3,
        0xf5, 0xff,
        0xf6, 0x0,
        0xf7, 0x3f,
        0xf8, 0x0,
        0xf9, 0x0,
        0xfa, 0xff,
        0xfb, 0xff,
        0xfc, 0x3f,
        0xfd, 0xff,
        0xfe, 0xff,
        0xff, 0xff,
        0x3, 0x4,

        /* Setup the Diter to Pattern33 */
        0x80, 0xdd,
        0x81, 0xdd,
        0x82, 0x33,
        0x83, 0x33,
        0x84, 0xdd,
        0x85, 0xdd,
        0x86, 0x33,
        0x87, 0x33,
        0x88, 0x33,
        0x89, 0x33,
        0x8a, 0x77,
        0x8b, 0x77,
        0x8c, 0x33,
        0x8d, 0x33,
        0x8e, 0x77,
        0x8f, 0x77,
        0x90, 0xdd,
        0x91, 0xdd,
        0x92, 0x33,
        0x93, 0x33,
        0x94, 0xdd,
        0x95, 0xdd,
        0x96, 0x33,
        0x97, 0x33,
        0x98, 0x33,
        0x99, 0x33,
        0x9a, 0x77,
        0x9b, 0x77,
        0x9c, 0x33,
        0x9d, 0x33,
        0x9e, 0x77,
        0x9f, 0x77,

        0x4, 0x20,
        0x5, 0x3,
        0x6, 0x56,
        0x7, 0x2,
        0x8, 0x1c,
        0x9, 0x0,
        0xa, 0x26,
        0xb, 0x0,
        0xc, 0x15,
        0xd, 0x4,
        0xe, 0x50,
        0xf, 0x4,
        0x10, 0xfa,
        0x11, 0x0,
        0x12, 0xc8,
        0x13, 0x0,
        0x14, 0x31,
        0x15, 0x23,
        0x16, 0x0,

        /* Enable DSTN panel */
        0x2, 0x64
    };
    unsigned char index, data;
    int i;

    gfx_delay_milliseconds(100);
    Draco9210GpioInit();
    Draco9210SetCS();
    Draco9210ToggleClock();
    Draco9210ToggleClock();
    Draco9210ToggleClock();
    Draco9210ToggleClock();
    Draco9210ClearCS();

#if defined(_WIN32)             /* For Windows   */
    for (i = 0; i < 10; i++) {
        _asm {
        out 0ED h, al}
    }

#elif defined(linux)            /* Linux                 */

#endif

    for (i = 0; i < 630; i += 2) {
        index = panelvalues[i];
        data = panelvalues[i + 1];
        Draco9210WriteReg(index, data);
    }

}

static void
DracoWriteData(unsigned char data)
{
    int i;
    unsigned char mask = 0x80, databit;

    for (i = 0; i < 8; i++) {

        databit = data & mask;
        if (data & mask) {
            Draco9210SetDataOut();
        }
        else {
            Draco9210ClearDataOut();
        }
        mask >>= 1;
        Draco9210ToggleClock();
    }
}

static void
DracoReadData(unsigned char *data)
{
    int i;
    unsigned char tmp = 0, readbit;

    Draco9210ClearDataOut();
    Draco9210ToggleClock();
    for (i = 0; i < 7; i++) {
        readbit = Draco9210ReadDataIn();
        tmp |= (readbit & 0x1);
        tmp <<= 1;
        Draco9210ToggleClock();
    }
    readbit = Draco9210ReadDataIn();
    tmp |= (readbit & 0x1);
    *data = tmp;
}

#if defined(_WIN32)             /* For Windows */

void
Draco9210GpioInit()
{
    _asm {
    pushf
            cli
            mov dx, 0 CF8h
            mov eax, CX55x0_ID + 090 h
            out dx, eax
            mov dx, 0 CFCh mov al, 0 CFh mov ah, 00 h out dx, ax popf}
}

void
Draco9210SetCS()
{
    _asm {
        pushf;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
        Point to PCI data register (CFCh)
mov dx, 0 CFCh
            in ax, dx
            and ah, 30 h
            mov ah, c92DataReg
            or ah, CS9210 mov c92DataReg, ah out dx, ax popf}} void
Draco9210ClearCS()
{
    _asm {
        pushf;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
        Point to PCI data register (CFCh)
        mov dx, 0 CFCh;
Set CS LOW
            in ax, dx
            mov ah, c92DataReg
            and ah, NOT CS9210 mov c92DataReg, ah out dx, ax popf}} void
Draco9210SetDataOut()
{
    _asm {
        pushf;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
        Point to PCI data register (CFCh)
        mov dx, 0 CFCh;
Set DATA HIGH
            in ax, dx
            mov ah, c92DataReg
            or ah, DATAOUT9210 mov c92DataReg, ah out dx, ax popf}} void
Draco9210ClearDataOut()
{
    _asm {
        pushf;
        Point to PCI address register
        mov dx, 0 CF8h mov eax, CX55x0_ID + 090 h;

        ;
        55 XX GPIO data register out dx, eax;
        Point to PCI data register (CFCh)
        mov dx, 0 CFCh;
Set Data LOW
            in ax, dx
            mov ah, c92DataReg
            and ah, NOT DATAOUT9210 mov c92DataReg, ah out dx, ax popf}}
    unsigned char
Draco9210ReadDataIn()
{
    unsigned char readdata;

    _asm {
        pushf;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
        Point to PCI data register (CFCh)
        mov dx, 0F Ch in ax, dx;
        Preserve just Data IN bit and ah, DATAIN9210 mov al, ah cmp al, 0;
        Is it LOW ? je readDataLow;
    must be HIGH mov al, 1 readDataLow:mov readdata, al popf} return (readdata);
}

void
Draco9210ToggleClock()
{
    _asm {
        pushf;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h;
        Point to PCI data register (CFCh)
        out dx, eax mov dx, 0 CFCh;
        SET CLOCK in ax, dx mov ah, c92DataReg or ah, CLOCK9210 mov c92DataReg, ah out dx, ax out 0ED h, al     /* IOPAUSE      */
        ;
        Point to PCI address register mov dx, 0 CF8h;
        55 XX GPIO data register mov eax, CX55x0_ID + 090 h out dx, eax;
        Point to PCI data register (CFCh)
        mov dx, 0 CFCh;

        ;
CLEAR CLOCK
            in ax, dx
            mov ah, c92DataReg
            and ah, NOT CLOCK9210 mov c92DataReg, ah out dx, ax popf}}
#elif defined(linux)            /* Linux         */

void
Draco9210GpioInit()
{
}

void
Draco9210SetCS()
{
}

void
Draco9210ClearCS()
{
}

void
Draco9210SetDataOut()
{
}

void
Draco9210ClearDataOut()
{
}

unsigned char
Draco9210ReadDataIn()
{
}

void
Draco9210ToggleClock()
{
}

#endif

unsigned char
Draco9210ReadReg(unsigned char index)
{
    unsigned char data;

    Draco9210SetCS();
    Draco9210ToggleClock();
    Draco9210SetDataOut();
    Draco9210ToggleClock();
    Draco9210ClearDataOut();
    Draco9210ToggleClock();
    Draco9210ClearDataOut();
    Draco9210ToggleClock();
    Draco9210ClearDataOut();
    Draco9210ToggleClock();

    DracoWriteData(index);
    DracoReadData(&data);

    return (data);
}

void
Draco9210WriteReg(unsigned char index, unsigned char data)
{

    Draco9210SetCS();
    Draco9210ToggleClock();

    Draco9210SetDataOut();
    Draco9210ToggleClock();

    Draco9210ClearDataOut();
    Draco9210ToggleClock();

    Draco9210ClearDataOut();
    Draco9210ToggleClock();

    Draco9210SetDataOut();
    Draco9210ToggleClock();

    DracoWriteData(index);
    DracoWriteData(data);

    Draco9210ClearDataOut();
    Draco9210ToggleClock();

    Draco9210ClearCS();
    Draco9210ToggleClock();
    Draco9210ToggleClock();

}