summaryrefslogtreecommitdiff
path: root/src/gfx/tv_1200.c
blob: bada40625bfe1101666fa5bac7d5378ebf1a833f (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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
/* $XFree86$ */
/*
 * $Workfile: tv_1200.c $
 *
 * This file contains routines to control the SC1200 TVOUT and TV encoder.
 *
 * NSC_LIC_ALTERNATIVE_PREAMBLE
 *
 * Revision 1.0
 *
 * National Semiconductor Alternative GPL-BSD License
 *
 * National Semiconductor Corporation licenses this software 
 * ("Software"):
 *
 *      Durango
 *
 * under one of the two following licenses, depending on how the 
 * Software is received by the Licensee.
 * 
 * If this Software is received as part of the Linux Framebuffer or
 * other GPL licensed software, then the GPL license designated 
 * NSC_LIC_GPL applies to this Software; in all other circumstances 
 * then the BSD-style license designated NSC_LIC_BSD shall apply.
 *
 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */

/* NSC_LIC_BSD
 *
 * National Semiconductor Corporation Open Source License for Durango
 *
 * (BSD License with Export Notice)
 *
 * Copyright (c) 1999-2001
 * National Semiconductor Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met: 
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials provided 
 *     with the distribution. 
 *
 *   * Neither the name of the National Semiconductor Corporation nor 
 *     the names of its contributors may be used to endorse or promote 
 *     products derived from this software without specific prior 
 *     written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE.
 *
 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 
 * YOUR JURISDICTION. It is licensee's responsibility to comply with 
 * any export regulations applicable in licensee's jurisdiction. Under 
 * CURRENT (2001) U.S. export regulations this software 
 * is eligible for export from the U.S. and can be downloaded by or 
 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 
 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 
 * Syria, Sudan, Afghanistan and any other country to which the U.S. 
 * has embargoed goods and services. 
 *
 * END_NSC_LIC_BSD */

/* NSC_LIC_GPL
 *
 * National Semiconductor Corporation Gnu General Public License for Durango
 *
 * (GPL License with Export Notice)
 *
 * Copyright (c) 1999-2001
 * National Semiconductor Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted under the terms of the GNU General 
 * Public License as published by the Free Software Foundation; either 
 * version 2 of the License, or (at your option) any later version  
 *
 * In addition to the terms of the GNU General Public License, neither 
 * the name of the National Semiconductor Corporation nor the names of 
 * its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE, 
 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE. See the GNU General Public License for more details. 
 *
 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 
 * YOUR JURISDICTION. It is licensee's responsibility to comply with 
 * any export regulations applicable in licensee's jurisdiction. Under 
 * CURRENT (2001) U.S. export regulations this software 
 * is eligible for export from the U.S. and can be downloaded by or 
 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 
 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 
 * Syria, Sudan, Afghanistan and any other country to which the U.S. 
 * has embargoed goods and services. 
 *
 * You should have received a copy of the GNU General Public License 
 * along with this file; if not, write to the Free Software Foundation, 
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 *
 * END_NSC_LIC_GPL */

int sc1200_set_tv_format(TVStandardType format, GfxOnTVType resolution);
int sc1200_set_tv_output(int output);
int sc1200_set_tv_enable(int enable);
int sc1200_set_tv_flicker_filter(int ff);
int sc1200_set_tv_sub_carrier_reset(int screset);
int sc1200_set_tv_vphase(int vphase);
int sc1200_set_tv_YC_delay(int delay);
int sc1200_set_tvenc_reset_interval(int interval);
int sc1200_set_tv_cc_enable(int enable);
int sc1200_set_tv_cc_data(unsigned char data1, unsigned char data2);
int sc1200_set_tv_display(int width, int height);
int sc1200_test_tvout_odd_field(void);
int sc1200_test_tvenc_odd_field(void);
int sc1200_set_tv_field_status_invert(int enable);
int sc1200_get_tv_vphase(void);
int sc1200_get_tv_enable(unsigned int *p_on);
int sc1200_get_tv_output(void);
int sc1200_get_tv_mode_count(TVStandardType format);
int sc1200_get_tv_display_mode(int *width, int *height, int *bpp, int *hz);
int sc1200_get_tv_display_mode_frequency(unsigned short width,
					 unsigned short height,
					 TVStandardType format,
					 int *frequency);
int sc1200_is_tv_display_mode_supported(unsigned short width,
					unsigned short height,
					TVStandardType format);

int sc1200_get_tv_standard(unsigned long *p_standard);
int sc1200_get_available_tv_standards(unsigned long *p_standards);
int sc1200_set_tv_standard(unsigned long standard);
int sc1200_get_tv_vga_mode(unsigned long *p_vga_mode);
int sc1200_get_available_tv_vga_modes(unsigned long *p_vga_modes);
int sc1200_set_tv_vga_mode(unsigned long vga_mode);
int sc1200_get_tvout_mode(unsigned long *p_tvout_mode);
int sc1200_set_tvout_mode(unsigned long tvout_mode);
int sc1200_get_sharpness(int *p_sharpness);
int sc1200_set_sharpness(int sharpness);
int sc1200_get_flicker_filter(int *p_flicker);
int sc1200_set_flicker_filter(int flicker);
int sc1200_get_overscan(int *p_x, int *p_y);
int sc1200_set_overscan(int x, int y);
int sc1200_get_position(int *p_x, int *p_y);
int sc1200_set_position(int x, int y);
int sc1200_get_color(int *p_color);
int sc1200_set_color(int color);
int sc1200_get_brightness(int *p_brightness);
int sc1200_set_brightness(int brightness);
int sc1200_get_contrast(int *p_contrast);
int sc1200_set_contrast(int constrast);
int sc1200_get_yc_filter(unsigned int *p_yc_filter);
int sc1200_set_yc_filter(unsigned int yc_filter);
int sc1200_get_aps_trigger_bits(unsigned int *p_trigger_bits);
int sc1200_set_aps_trigger_bits(unsigned int trigger_bits);
unsigned char cc_add_parity_bit(unsigned char data);

/*-----------------------------------------------------------------------------
 * gfx_set_tv_format
 *
 * This routine sets the TV encoder registers to the specified format
 * and resolution.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_format(TVStandardType format, GfxOnTVType resolution)
#else
int
gfx_set_tv_format(TVStandardType format, GfxOnTVType resolution)
#endif
{
   unsigned long ctrl2, mode;

   /* Save TV output mode */
   ctrl2 =
	 READ_VID32(SC1200_TVENC_TIM_CTRL_2) & (SC1200_TVENC_OUTPUT_YCBCR |
						SC1200_TVENC_CFS_MASK);
   /* Save flicker filter setting */
   mode = READ_VID32(SC1200_TVOUT_HORZ_SCALING) &
	 SC1200_TVOUT_FLICKER_FILTER_MASK;

   switch (format) {
   case TV_STANDARD_NTSC:
      /* Horizontal Sync Start is 848 */
      /* Horizontal Sync End is 856 */
      WRITE_VID32(SC1200_TVOUT_HORZ_SYNC, 0x03580350);
      /* Vertical Sync Start is 0 */
      /* Vertical Sync End is 1 */
      /* Vertical Display Start Skew is 1 */
      /* Vertical Display End Skew is 1 */
      WRITE_VID32(SC1200_TVOUT_VERT_SYNC, 0x05001000);
      /* Disable vertical down scaling, take all lines */
      if (gfx_chip_revision <= SC1200_REV_B3)
	 WRITE_VID32(SC1200_TVOUT_VERT_DOWNSCALE, 0xffffffff);
      /* Enable video timing */
      /* Reset sub carrier every two frames */
      /* Disable BLANK */
      /* Enable color burst */
      /* Add the IRE offset */
      /* NTSC color encoding */
      /* Video generator timing is 525 lines / 60Hz */
      /* Horizontal and Vertical counters are initialized to HPHASE & VPHASE */
      /* VPHASE is 2, HPHASE is 0x50 */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1, 0xa2a01050);
      /* Increase horizontal blanking interval */
      /* Low Water Mark for Y is 0x1F */
      /* Low Water Mark for Cb is 0xF */
      /* HUE is 0 */
      /* SCPHASE is 0xF9 */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2, 0x9ff000f9 | ctrl2);
      /* Subcarrier Frequency is 3.579545 MHz */
      WRITE_VID32(SC1200_TVENC_SUB_FREQ, 0x21f07c1f);
      /* VSTART is 18, HSTART is 113 */
      WRITE_VID32(SC1200_TVENC_DISP_POS, 0x00120071);
      /* Display size: HEIGHT is 239, WIDTH is 719 */
      WRITE_VID32(SC1200_TVENC_DISP_SIZE, 0x00ef02cf);
      switch (resolution) {
      case GFX_ON_TV_SQUARE_PIXELS:
	 if (gfx_chip_revision <= SC1200_REV_B3) {
	    /* Horizontal Display start is 116 */
	    /* Total number of pixels per line is 857 */
	    WRITE_VID32(SC1200_TVOUT_HORZ_TIM, 0x00740359);
	    /* HSYNC generated in the TV Encoder module */
	    /* Interval between resets of TV Encoder is once every odd field */
	    /* Enable Horizontal interpolation */
	    /* Enable Horizontal up scaling 9/8 */
	    /* Disable Horizontal downscale */
	    WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x10020700 | mode);
	    /* Horizontal display end is 919, i.e. 720 active pixels */
	    /* Total number of display lines per field is 240 */
	    WRITE_VID32(SC1200_TVOUT_LINE_END, 0x039700f0);
	 } else {			/* Use new scaler available in Rev. C */
	    /* Horizontal Display start is 111 */
	    /* Total number of pixels per line is 857 */
	    WRITE_VID32(SC1200_TVOUT_HORZ_TIM, 0x006f0359);
	    /* HSYNC generated in the TV Encoder module */
	    /* Interval between resets of TV Encoder is once every odd field */
	    /* Enable Horizontal interpolation */
	    /* Disable Horizontal up scaling 9/8 */
	    /* Disable Horizontal downscale */
	    WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x10020500 | mode);
	    /* Set Horizontal upscaling to 64/58 (~ 11/10) */
	    WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE, 0x3A000000);
	    /* Horizontal display end is 900, i.e. 706 active pixels */
	    /* Total number of display lines per field is 240 */
	    WRITE_VID32(SC1200_TVOUT_LINE_END, 0x038400f0);
	 }
	 break;
      case GFX_ON_TV_NO_SCALING:
	 /* Horizontal Display start is 116 */
	 /* Total number of pixels per line is 857 */
	 WRITE_VID32(SC1200_TVOUT_HORZ_TIM, 0x00740359);
	 /* HSYNC generated in the TV Encoder module */
	 /* Interval between resets of TV Encoder is once every odd field */
	 /* Enable Horizontal interpolation */
	 /* Disable Horizontal up scaling 9/8 */
	 /* Disable Horizontal downscale */
	 WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x10020500 | mode);
	 /* Disable Horizontal scaling (set to 64/64) */
	 if (gfx_chip_revision >= SC1200_REV_C1)
	    WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE, 0x40000000);
	 /* Horizontal display end is 919, i.e. 720 active pixels */
	 /* Total number of display lines per field is 240 */
	 WRITE_VID32(SC1200_TVOUT_LINE_END, 0x039700f0);
	 break;
      default:
	 return (GFX_STATUS_BAD_PARAMETER);
      }
      break;
   case TV_STANDARD_PAL:
      /* Horizontal Sync Start is 854 */
      /* Horizontal Sync End is 862 */
      WRITE_VID32(SC1200_TVOUT_HORZ_SYNC, 0x035e0356);
      /* Vertical Sync Start is 0 */
      /* Vertical Sync End is 1 */
      /* Vertical Display Start Skew is 1 */
      /* Vertical Display End Skew is 1 */
      WRITE_VID32(SC1200_TVOUT_VERT_SYNC, 0x05001000);
      /* Disable vertical down scaling, take all lines */
      if (gfx_chip_revision <= SC1200_REV_B3)
	 WRITE_VID32(SC1200_TVOUT_VERT_DOWNSCALE, 0xffffffff);
      /* Enable video timing */
      /* Never reset sub carrier (should be every 4 frames but doesn't work with genlock) */
      /* Disable BLANK */
      /* Enable color burst */
      /* Do not add the IRE offset */
      /* NTSC color encoding */
      /* Video generator timing is 625 lines / 50Hz */
      /* Horizontal and Vertical counters are initialized to HPHASE & VPHASE */
      /* VPHASE is 2, HPHASE is 50 */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1, 0xB1201050);
      /* Increase horizontal blanking interval */
      /* Low Water Mark for Y is 0x1F */
      /* Low Water Mark for Cb is 0xF */
      /* HUE is 0 */
      /* SCPHASE is 0xD9 */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2, 0x9ff000d9 | ctrl2);
      /* Subcarrier Frequency is 4.43361875 MHz */
      WRITE_VID32(SC1200_TVENC_SUB_FREQ, 0x2a098acb);
      /* VSTART is 22, HSTART is 123 */
      WRITE_VID32(SC1200_TVENC_DISP_POS, 0x0016007b);
      /* Display size: HEIGHT is 287, WIDTH is 719 */
      WRITE_VID32(SC1200_TVENC_DISP_SIZE, 0x011f02cf);
      switch (resolution) {
      case GFX_ON_TV_NO_SCALING:
	 /* Horizontal Display start is 124 */
	 /* Total number of pixels per line is 863 */
	 WRITE_VID32(SC1200_TVOUT_HORZ_TIM, 0x007c035f);
	 /* HSYNC generated in the TV Encoder module */
	 /* Interval between resets of TV Encoder is once every odd field */
	 /* Enable Horizontal interpolation */
	 /* Disable Horizontal up scaling 9/8 */
	 /* Disable Horizontal downscale */
	 WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x10020500 | mode);
	 /* Disable Horizontal scaling (set to 64/64) */
	 if (gfx_chip_revision >= SC1200_REV_C1)
	    WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE, 0x40000000);
	 /* Horizontal display end is 924, i.e. 720 active pixels */
	 /* Total number of display lines per field is 288 */
	 WRITE_VID32(SC1200_TVOUT_LINE_END, 0x039c0120);
	 break;
      case GFX_ON_TV_SQUARE_PIXELS:
	 /* Horizontal Display start is 122 */
	 /* Total number of pixels per line is 863 */
	 WRITE_VID32(SC1200_TVOUT_HORZ_TIM, 0x007a035f);
	 if (gfx_chip_revision <= SC1200_REV_B3) {
	    /* HSYNC generated in the TV Encoder module */
	    /* Interval between resets of TV Encoder is once every odd field */
	    /* Enable Horizontal interpolation */
	    /* Disable Horizontal up scaling 9/8 */
	    /* Horizontal downscale m/(m+1), m = 11, (i.e. 11/12 - closest possible to 54/59) */
	    WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x1002040b | mode);
	    /* Horizontal display end is 906, i.e. 704 active pixels */
	    /* Total number of display lines per field is 288 */
	    WRITE_VID32(SC1200_TVOUT_LINE_END, 0x038a0120);
	 } else {
	    /* HSYNC generated in the TV Encoder module */
	    /* Interval between resets of TV Encoder is once every odd field */
	    /* Enable Horizontal interpolation */
	    /* Disable Horizontal up scaling 9/8 */
	    /* Disable Horizontal downscale */
	    WRITE_VID32(SC1200_TVOUT_HORZ_SCALING, 0x10020500 | mode);
	    /* Set Horizontal down scaling to 64/70 (closest possible to 54/59) */
	    WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE, 0x46000000);
	    /* Horizontal display end is 904, i.e. 702 active pixels */
	    /* Total number of display lines per field is 288 */
	    WRITE_VID32(SC1200_TVOUT_LINE_END, 0x03880120);
	 }
	 break;
      default:
	 return (GFX_STATUS_BAD_PARAMETER);
      }
      break;
   default:
      return (GFX_STATUS_BAD_PARAMETER);
   }
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_output
 *
 * This routine sets the TV encoder registers to the specified output type.
 * Supported output types are : S-VIDEO, Composite, YUV and SCART.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_output(int output)
#else
int
gfx_set_tv_output(int output)
#endif
{
   unsigned long ctrl2, ctrl3;

   ctrl2 = READ_VID32(SC1200_TVENC_TIM_CTRL_2);
   ctrl3 = READ_VID32(SC1200_TVENC_TIM_CTRL_3);
   ctrl2 &= ~(SC1200_TVENC_OUTPUT_YCBCR | SC1200_TVENC_CFS_MASK);
   ctrl3 &= ~(SC1200_TVENC_CM | SC1200_TVENC_SYNCMODE_MASK | SC1200_TVENC_CS);
   switch (output) {
   case TV_OUTPUT_COMPOSITE:
      /* Analog outputs provide Y, C and CVBS */
      /* Chrominance Lowpass filter is 1.3MHz (for composite video output) */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2, ctrl2 | SC1200_TVENC_CFS_CVBS);
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_3, ctrl3);
      break;
   case TV_OUTPUT_S_VIDEO:
      /* Analog outputs provide Y, C and CVBS */
      /* Chrominance Lowpass filter is 1.8MHz (for S-video output) */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2, ctrl2 | SC1200_TVENC_CFS_SVIDEO);
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_3, ctrl3);
      break;
   case TV_OUTPUT_YUV:
      /* Analog outputs provide Y, Cb and Cr */
      /* A 7.5 IRE setup is applied to the output */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2,
		  ctrl2 | SC1200_TVENC_OUTPUT_YCBCR |
		  SC1200_TVENC_CFS_BYPASS);
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_3,
		  ctrl3 | SC1200_TVENC_CM | SC1200_TVENC_CS);
      break;
   case TV_OUTPUT_SCART:
      /* Analog outputs provide SCART (RGB and CVBS) */
      /* Sync is added to green signal */
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_2, ctrl2 | SC1200_TVENC_CFS_CVBS);
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_3,
		  ctrl3 | SC1200_TVENC_CM | SC1200_TVENC_SYNC_ON_GREEN);
      break;
   default:
      return (GFX_STATUS_BAD_PARAMETER);
   }

   /* Adjusts the internal voltage reference */
   ctrl2 = READ_VID32(SC1200_TVENC_DAC_CONTROL);
   ctrl2 &= ~SC1200_TVENC_TRIM_MASK;

   /* Bypass for issue #926 : Inadequate chroma level of S-Video output */
   if ((gfx_chip_revision == SC1200_REV_B3) && (output == TV_OUTPUT_S_VIDEO))
      ctrl2 |= 0x7;
   else
      ctrl2 |= 0x5;

   WRITE_VID32(SC1200_TVENC_DAC_CONTROL, ctrl2);

   /* Disable 4:2:2 to 4:4:4 converter interpolation */
   WRITE_VID32(SC1200_TVOUT_DEBUG, SC1200_TVOUT_CONVERTER_INTERPOLATION);

   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_enable
 *
 * This routine enables or disables the TV output.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_enable(int enable)
#else
int
gfx_set_tv_enable(int enable)
#endif
{
   unsigned long value_tim, value_dac;

   value_tim = READ_VID32(SC1200_TVENC_TIM_CTRL_1);
   value_dac = READ_VID32(SC1200_TVENC_DAC_CONTROL);

   if (enable) {
      value_tim |= SC1200_TVENC_VIDEO_TIMING_ENABLE;
      value_dac &= ~SC1200_TVENC_POWER_DOWN;
      /* ENABLE GRAPHICS DISPLAY LOGIC IN VIDEO PROCESSOR */
      gfx_set_screen_enable(1);
   } else {
      value_tim &= ~SC1200_TVENC_VIDEO_TIMING_ENABLE;
      value_dac |= SC1200_TVENC_POWER_DOWN;
      /* Do not disable the graphics display logic because it might be needed for CRT */
   }

   WRITE_VID32(SC1200_TVENC_TIM_CTRL_1, value_tim);
   WRITE_VID32(SC1200_TVENC_DAC_CONTROL, value_dac);

   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_flicker_filter
 *
 * This routine configures the TV out flicker filter.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_flicker_filter(int ff)
#else
int
gfx_set_tv_flicker_filter(int ff)
#endif
{
   unsigned long mode;

   mode = READ_VID32(SC1200_TVOUT_HORZ_SCALING);
   mode &= ~SC1200_TVOUT_FLICKER_FILTER_MASK;
   switch (ff) {
   case TV_FLICKER_FILTER_NONE:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  mode | SC1200_TVOUT_FLICKER_FILTER_DISABLED);
      break;
   case TV_FLICKER_FILTER_NORMAL:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  mode | SC1200_TVOUT_FLICKER_FILTER_FOURTH_HALF_FOURTH);
      break;
   case TV_FLICKER_FILTER_INTERLACED:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  mode | SC1200_TVOUT_FLICKER_FILTER_HALF_ONE_HALF);
      break;
   default:
      return GFX_STATUS_BAD_PARAMETER;
   }
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_sub_carrier_reset
 *
 * This routine configures the TV encoder sub carrier reset interval.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_sub_carrier_reset(int screset)
#else
int
gfx_set_tv_sub_carrier_reset(int screset)
#endif
{
   unsigned long mode;

   mode = READ_VID32(SC1200_TVENC_TIM_CTRL_1);
   mode &= ~SC1200_TVENC_SUB_CARRIER_RESET_MASK;
   switch (screset) {
   case TV_SUB_CARRIER_RESET_NEVER:
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1,
		  mode | SC1200_TVENC_SUB_CARRIER_RESET_NEVER);
      break;
   case TV_SUB_CARRIER_RESET_EVERY_TWO_LINES:
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1,
		  mode | SC1200_TVENC_SUB_CARRIER_RESET_EVERY_TWO_LINES);
      break;
   case TV_SUB_CARRIER_RESET_EVERY_TWO_FRAMES:
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1,
		  mode | SC1200_TVENC_SUB_CARRIER_RESET_EVERY_TWO_FRAMES);
      break;
   case TV_SUB_CARRIER_RESET_EVERY_FOUR_FRAMES:
      WRITE_VID32(SC1200_TVENC_TIM_CTRL_1,
		  mode | SC1200_TVENC_SUB_CARRIER_RESET_EVERY_FOUR_FRAMES);
      break;
   default:
      return GFX_STATUS_BAD_PARAMETER;
   }
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_vphase
 *
 * This routine sets the tv encoder VPHASE value.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_vphase(int vphase)
#else
int
gfx_set_tv_vphase(int vphase)
#endif
{
   unsigned long mode = READ_VID32(SC1200_TVENC_TIM_CTRL_1);

   mode &= ~SC1200_TVENC_VPHASE_MASK;
   mode |= (vphase << SC1200_TVENC_VPHASE_POS) & SC1200_TVENC_VPHASE_MASK;
   WRITE_VID32(SC1200_TVENC_TIM_CTRL_1, mode);
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_YC_delay
 *
 * This routine configures the TV out Y/C delay.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_YC_delay(int delay)
#else
int
gfx_set_tv_YC_delay(int delay)
#endif
{
   unsigned long mode;

   /* This feature is implemented in Rev C1 */
   if (gfx_chip_revision < SC1200_REV_C1)
      return (GFX_STATUS_OK);

   mode = READ_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE);
   mode &= ~SC1200_TVOUT_YC_DELAY_MASK;
   switch (delay) {
   case TV_YC_DELAY_NONE:
      WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE,
		  mode | SC1200_TVOUT_YC_DELAY_NONE);
      break;
   case TV_Y_DELAY_ONE_PIXEL:
      WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE,
		  mode | SC1200_TVOUT_Y_DELAY_ONE_PIXEL);
      break;
   case TV_C_DELAY_ONE_PIXEL:
      WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE,
		  mode | SC1200_TVOUT_C_DELAY_ONE_PIXEL);
      break;
   case TV_C_DELAY_TWO_PIXELS:
      WRITE_VID32(SC1200_TVOUT_HORZ_PRE_ENCODER_SCALE,
		  mode | SC1200_TVOUT_C_DELAY_TWO_PIXELS);
      break;
   default:
      return GFX_STATUS_BAD_PARAMETER;
   }
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tvenc_reset_interval
 *
 * This routine sets the interval between external resets of the TV encoder
 * timing generator by the TV out.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tvenc_reset_interval(int interval)
#else
int
gfx_set_tvenc_reset_interval(int interval)
#endif
{
   unsigned long value;

   value = READ_VID32(SC1200_TVOUT_HORZ_SCALING);
   value &= ~SC1200_TVENC_EXTERNAL_RESET_INTERVAL_MASK;
   switch (interval) {
   case TVENC_RESET_EVERY_ODD_FIELD:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  value | SC1200_TVENC_EXTERNAL_RESET_EVERY_ODD_FIELD);
      break;
   case TVENC_RESET_EVERY_EVEN_FIELD:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  value | SC1200_TVENC_EXTERNAL_RESET_EVERY_EVEN_FIELD);
      break;
   case TVENC_RESET_NEXT_ODD_FIELD:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  value | SC1200_TVENC_EXTERNAL_RESET_NEXT_ODD_FIELD);
      break;
   case TVENC_RESET_NEXT_EVEN_FIELD:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  value | SC1200_TVENC_EXTERNAL_RESET_NEXT_EVEN_FIELD);
      break;
   case TVENC_RESET_EVERY_FIELD:
      WRITE_VID32(SC1200_TVOUT_HORZ_SCALING,
		  value | SC1200_TVENC_EXTERNAL_RESET_EVERY_FIELD);
      break;
   case TVENC_RESET_EVERY_X_ODD_FIELDS:
   case TVENC_RESET_EVERY_X_EVEN_FIELDS:
      return GFX_STATUS_UNSUPPORTED;
   default:
      return GFX_STATUS_BAD_PARAMETER;
   }
   return (GFX_STATUS_OK);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_cc_enable
 *
 * This routine enables or disables the use of the hardware CC registers 
 * in the TV encoder.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_cc_enable(int enable)
#else
int
gfx_set_tv_cc_enable(int enable)
#endif
{
   unsigned long value;

   value = READ_VID32(SC1200_TVENC_CC_CONTROL);
   value &= ~(0x0005F);
   if (enable)
      value |= 0x51;
   WRITE_VID32(SC1200_TVENC_CC_CONTROL, value);
   return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_tv_display
 *
 * This routine sets the timings in the display controller to support a 
 * TV resolution.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_display(int width, int height)
#else
int
gfx_set_tv_display(int width, int height)
#endif
{
   DISPLAYMODE *pMode;
   unsigned int i;

   for (i = 0; i < NUM_TV_MODES; i++) {
      pMode = &TVTimings[i];
      if ((unsigned)width == pMode->hactive
	  && (unsigned)height == pMode->vactive)
	 break;
   }

   if (i == NUM_TV_MODES)
      return 0;

   gfx_set_display_timings(gfx_get_display_bpp(),
			   (unsigned short)pMode->flags, pMode->hactive,
			   pMode->hblankstart, pMode->hsyncstart,
			   pMode->hsyncend, pMode->hblankend, pMode->htotal,
			   pMode->vactive, pMode->vblankstart,
			   pMode->vsyncstart, pMode->vsyncend,
			   pMode->vblankend, pMode->vtotal, pMode->frequency);

   return 1;
}

/*-----------------------------------------------------------------------------
 * cc_add_parity_bit
 *
 * This routine adds the (odd) parity bit to the data character.
 *-----------------------------------------------------------------------------
 */
unsigned char
cc_add_parity_bit(unsigned char data)
{
   int i, num = 0;
   unsigned char d = data;

   for (i = 0; i < 7; i++) {
      if (d & 0x1)
	 num++;
      d >>= 1;
   }
   if (num & 0x1)
      return (data & ~0x80);
   else
      return (data | 0x80);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_cc_data
 *
 * This routine writes the two specified characters to the CC data register 
 * of the TV encoder.
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_cc_data(unsigned char data1, unsigned char data2)
#else
int
gfx_set_tv_cc_data(unsigned char data1, unsigned char data2)
#endif
{
   unsigned long value;

   value = cc_add_parity_bit(data1) | (cc_add_parity_bit(data2) << 8);
   WRITE_VID32(SC1200_TVENC_CC_DATA, value);
   return (0);
}

/*---------------------------------------------------------------------------
 * gfx_test_tvout_odd_field
 * 
 * This routine returns 1 if the current TVout field is odd. Otherwise returns 0.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_test_tvout_odd_field(void)
#else
int
gfx_test_tvout_odd_field(void)
#endif
{
   unsigned long debug = READ_VID32(SC1200_TVOUT_DEBUG);

   WRITE_VID32(SC1200_TVOUT_DEBUG, debug | SC1200_TVOUT_FIELD_STATUS_TV);
   if (READ_VID32(SC1200_TVOUT_DEBUG) & SC1200_TVOUT_FIELD_STATUS_EVEN)
      return (0);
   else
      return (1);
}

/*---------------------------------------------------------------------------
 * gfx_test_tvenc_odd_field
 * 
 * This routine returns 1 if the current TV encoder field is odd. Otherwise returns 0.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_test_tvenc_odd_field(void)
#else
int
gfx_test_tvenc_odd_field(void)
#endif
{
   unsigned long debug = READ_VID32(SC1200_TVOUT_DEBUG);

   WRITE_VID32(SC1200_TVOUT_DEBUG, debug & ~SC1200_TVOUT_FIELD_STATUS_TV);
   if (READ_VID32(SC1200_TVOUT_DEBUG) & SC1200_TVOUT_FIELD_STATUS_EVEN)
      return (0);
   else
      return (1);
}

/*-----------------------------------------------------------------------------
 * gfx_set_tv_field_status_invert
 *
 * This routines determines whether the tvout/tvencoder field status bit is
 * inverted (enable = 1) or not (enable = 0).
 *-----------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_set_tv_field_status_invert(int enable)
#else
int
gfx_set_tv_field_status_invert(int enable)
#endif
{
   unsigned long value;

   value = READ_VID32(SC1200_TVOUT_DEBUG);

   if (enable) {
      value |= SC1200_TVOUT_FIELD_STATUS_INVERT;
   } else {
      value &= ~(SC1200_TVOUT_FIELD_STATUS_INVERT);
   }

   WRITE_VID32(SC1200_TVOUT_DEBUG, value);

   return (GFX_STATUS_OK);
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_vphase
 * 
 * This routine returns the tv encoder vertical phase.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_vphase(void)
#else
int
gfx_get_tv_vphase(void)
#endif
{
   unsigned long mode = READ_VID32(SC1200_TVENC_TIM_CTRL_1);

   return (int)((mode & SC1200_TVENC_VPHASE_MASK) >> SC1200_TVENC_VPHASE_POS);
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_enable
 * 
 * This routine returns the current tv enable status
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_enable(unsigned int *p_on)
#else
int
gfx_get_tv_enable(unsigned int *p_on)
#endif
{
   unsigned long control = READ_VID32(SC1200_TVENC_DAC_CONTROL);

   *p_on = (unsigned int)(!(control & SC1200_TVENC_POWER_DOWN));

   return GFX_STATUS_OK;
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_output
 * 
 * This routine returns the current programmed TV output type.  It does not
 * detect invalid configurations.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_output(void)
#else
int
gfx_get_tv_output(void)
#endif
{
   unsigned long ctrl2, ctrl3;
   int format = 0;

   ctrl2 = READ_VID32(SC1200_TVENC_TIM_CTRL_2);
   ctrl3 = READ_VID32(SC1200_TVENC_TIM_CTRL_3);

   if ((ctrl2 & SC1200_TVENC_CFS_MASK) == SC1200_TVENC_CFS_SVIDEO)
      format = TV_OUTPUT_S_VIDEO;
   else if (ctrl2 & SC1200_TVENC_OUTPUT_YCBCR)
      format = TV_OUTPUT_YUV;
   else if ((ctrl2 & SC1200_TVENC_CFS_MASK) == SC1200_TVENC_CFS_CVBS) {
      if (ctrl3 & SC1200_TVENC_CM)
	 format = TV_OUTPUT_SCART;
      else
	 format = TV_OUTPUT_COMPOSITE;
   }

   return format;
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_mode_count
 * 
 * This routine returns the number of valid TV out resolutions.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_mode_count(TVStandardType format)
#else
int
gfx_get_tv_mode_count(TVStandardType format)
#endif
{
   unsigned int mode, count = 0;
   unsigned long flag;

   switch (format) {
   case TV_STANDARD_NTSC:
      flag = GFX_MODE_TV_NTSC;
      break;
   case TV_STANDARD_PAL:
      flag = GFX_MODE_TV_PAL;
      break;
   default:
      return 0;
   }

   for (mode = 0; mode < NUM_TV_MODES; mode++) {
      if (TVTimings[mode].flags & flag)
	 count++;
   }

   return count;
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_display_mode
 * 
 * This routine returns the current TV display parameters.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_display_mode(int *width, int *height, int *bpp, int *hz)
#else
int
gfx_get_tv_display_mode(int *width, int *height, int *bpp, int *hz)
#endif
{
   unsigned long frequency;
   unsigned long mode, flags;

   *width = gfx_get_hactive();
   *height = gfx_get_vactive();
   *bpp = gfx_get_display_bpp();
   frequency = gfx_get_clock_frequency();

   for (mode = 0; mode < NUM_TV_MODES; mode++) {
      if (TVTimings[mode].hactive == (unsigned short)(*width) &&
	  TVTimings[mode].vactive == (unsigned short)(*height) &&
	  TVTimings[mode].frequency == frequency) {
	 flags = TVTimings[mode].flags;

	 if (flags & GFX_MODE_TV_NTSC)
	    *hz = 60;
	 else if (flags & GFX_MODE_TV_PAL)
	    *hz = 50;
	 else
	    *hz = 0;
	 return (1);
      }
   }

   return -1;
}

/*---------------------------------------------------------------------------
 * gfx_get_tv_display_mode_frequency
 *
 * This routine returns the PLL frequency of a given TV mode.
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_get_tv_display_mode_frequency(unsigned short width,
				     unsigned short height,
				     TVStandardType format, int *frequency)
#else
int
gfx_get_tv_display_mode_frequency(unsigned short width, unsigned short height,
				  TVStandardType format, int *frequency)
#endif
{
   unsigned long mode, flag;
   int retval = -1;

   *frequency = 0;

   switch (format) {
   case TV_STANDARD_NTSC:
      flag = GFX_MODE_TV_NTSC;
      break;
   case TV_STANDARD_PAL:
      flag = GFX_MODE_TV_PAL;
      break;
   default:
      return -1;
   }

   for (mode = 0; mode < NUM_TV_MODES; mode++) {
      if ((TVTimings[mode].hactive == width) &&
	  (TVTimings[mode].vactive == height) &&
	  (TVTimings[mode].flags & flag)) {
	 *frequency = TVTimings[mode].frequency;
	 retval = 1;
      }
   }
   return retval;
}

/*---------------------------------------------------------------------------
 * gfx_is_tv_display_mode_supported
 * 
 * Returns >= 0 if the mode is available, -1 if the mode could not be found
 *---------------------------------------------------------------------------
 */
#if GFX_TV_DYNAMIC
int
sc1200_is_tv_display_mode_supported(unsigned short width,
				    unsigned short height,
				    TVStandardType format)
#else
int
gfx_is_tv_display_mode_supported(unsigned short width, unsigned short height,
				 TVStandardType format)
#endif
{
   unsigned long mode, flag;

   switch (format) {
   case TV_STANDARD_NTSC:
      flag = GFX_MODE_TV_NTSC;
      break;
   case TV_STANDARD_PAL:
      flag = GFX_MODE_TV_PAL;
      break;
   default:
      return -1;
   }

   for (mode = 0; mode < NUM_TV_MODES; mode++) {
      if (TVTimings[mode].hactive == width &&
	  TVTimings[mode].vactive == height &&
	  (TVTimings[mode].flags & flag)) {
	 return ((int)mode);
      }
   }

   return -1;
}

/* END OF FILE */