forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atafb.c
3269 lines (2935 loc) · 88.9 KB
/
atafb.c
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
/*
* linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device
*
* Copyright (C) 1994 Martin Schaller & Roman Hodek
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* History:
* - 03 Jan 95: Original version by Martin Schaller: The TT driver and
* all the device independent stuff
* - 09 Jan 95: Roman: I've added the hardware abstraction (hw_switch)
* and wrote the Falcon, ST(E), and External drivers
* based on the original TT driver.
* - 07 May 95: Martin: Added colormap operations for the external driver
* - 21 May 95: Martin: Added support for overscan
* Andreas: some bug fixes for this
* - Jul 95: Guenther Kelleter <[email protected]>:
* Programmable Falcon video modes
* (thanks to Christian Cartus for documentation
* of VIDEL registers).
* - 27 Dec 95: Guenther: Implemented user definable video modes "user[0-7]"
* on minor 24...31. "user0" may be set on commandline by
* "R<x>;<y>;<depth>". (Makes sense only on Falcon)
* Video mode switch on Falcon now done at next VBL interrupt
* to avoid the annoying right shift of the screen.
* - 23 Sep 97: Juergen: added xres_virtual for cards like ProMST
* The external-part is legacy, therefore hardware-specific
* functions like panning/hardwarescrolling/blanking isn't
* supported.
* - 29 Sep 97: Juergen: added Romans suggestion for pan_display
* (var->xoffset was changed even if no set_screen_base avail.)
* - 05 Oct 97: Juergen: extfb (PACKED_PIXEL) is FB_PSEUDOCOLOR 'cause
* we know how to set the colors
* ext_*palette: read from ext_colors (former MV300_colors)
* write to ext_colors and RAMDAC
*
* To do:
* - For the Falcon it is not possible to set random video modes on
* SM124 and SC/TV, only the bootup resolution is supported.
*
*/
#define ATAFB_TT
#define ATAFB_STE
#define ATAFB_EXT
#define ATAFB_FALCON
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <asm/setup.h>
#include <linux/uaccess.h>
#include <asm/pgtable.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/atarihw.h>
#include <asm/atariints.h>
#include <asm/atari_stram.h>
#include <linux/fb.h>
#include <asm/atarikb.h>
#include "c2p.h"
#include "atafb.h"
#define SWITCH_ACIA 0x01 /* modes for switch on OverScan */
#define SWITCH_SND6 0x40
#define SWITCH_SND7 0x80
#define SWITCH_NONE 0x00
#define up(x, r) (((x) + (r) - 1) & ~((r)-1))
/*
* Interface to the world
*/
static int atafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
static int atafb_set_par(struct fb_info *info);
static int atafb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
unsigned int blue, unsigned int transp,
struct fb_info *info);
static int atafb_blank(int blank, struct fb_info *info);
static int atafb_pan_display(struct fb_var_screeninfo *var,
struct fb_info *info);
static void atafb_fillrect(struct fb_info *info,
const struct fb_fillrect *rect);
static void atafb_copyarea(struct fb_info *info,
const struct fb_copyarea *region);
static void atafb_imageblit(struct fb_info *info, const struct fb_image *image);
static int atafb_ioctl(struct fb_info *info, unsigned int cmd,
unsigned long arg);
static int default_par; /* default resolution (0=none) */
static unsigned long default_mem_req;
static int hwscroll = -1;
static int use_hwscroll = 1;
static int sttt_xres = 640, st_yres = 400, tt_yres = 480;
static int sttt_xres_virtual = 640, sttt_yres_virtual = 400;
static int ovsc_offset, ovsc_addlen;
/*
* Hardware parameters for current mode
*/
static struct atafb_par {
void *screen_base;
int yres_virtual;
u_long next_line;
#if defined ATAFB_TT || defined ATAFB_STE
union {
struct {
int mode;
int sync;
} tt, st;
#endif
#ifdef ATAFB_FALCON
struct falcon_hw {
/* Here are fields for storing a video mode, as direct
* parameters for the hardware.
*/
short sync;
short line_width;
short line_offset;
short st_shift;
short f_shift;
short vid_control;
short vid_mode;
short xoffset;
short hht, hbb, hbe, hdb, hde, hss;
short vft, vbb, vbe, vdb, vde, vss;
/* auxiliary information */
short mono;
short ste_mode;
short bpp;
u32 pseudo_palette[16];
} falcon;
#endif
/* Nothing needed for external mode */
} hw;
} current_par;
/* Don't calculate an own resolution, and thus don't change the one found when
* booting (currently used for the Falcon to keep settings for internal video
* hardware extensions (e.g. ScreenBlaster) */
static int DontCalcRes = 0;
#ifdef ATAFB_FALCON
#define HHT hw.falcon.hht
#define HBB hw.falcon.hbb
#define HBE hw.falcon.hbe
#define HDB hw.falcon.hdb
#define HDE hw.falcon.hde
#define HSS hw.falcon.hss
#define VFT hw.falcon.vft
#define VBB hw.falcon.vbb
#define VBE hw.falcon.vbe
#define VDB hw.falcon.vdb
#define VDE hw.falcon.vde
#define VSS hw.falcon.vss
#define VCO_CLOCK25 0x04
#define VCO_CSYPOS 0x10
#define VCO_VSYPOS 0x20
#define VCO_HSYPOS 0x40
#define VCO_SHORTOFFS 0x100
#define VMO_DOUBLE 0x01
#define VMO_INTER 0x02
#define VMO_PREMASK 0x0c
#endif
static struct fb_info fb_info = {
.fix = {
.id = "Atari ",
.visual = FB_VISUAL_PSEUDOCOLOR,
.accel = FB_ACCEL_NONE,
}
};
static void *screen_base; /* base address of screen */
static void *real_screen_base; /* (only for Overscan) */
static int screen_len;
static int current_par_valid;
static int mono_moni;
#ifdef ATAFB_EXT
/* external video handling */
static unsigned int external_xres;
static unsigned int external_xres_virtual;
static unsigned int external_yres;
/*
* not needed - atafb will never support panning/hardwarescroll with external
* static unsigned int external_yres_virtual;
*/
static unsigned int external_depth;
static int external_pmode;
static void *external_addr;
static unsigned long external_len;
static unsigned long external_vgaiobase;
static unsigned int external_bitspercol = 6;
/*
* JOE <[email protected]>:
* added card type for external driver, is only needed for
* colormap handling.
*/
enum cardtype { IS_VGA, IS_MV300 };
static enum cardtype external_card_type = IS_VGA;
/*
* The MV300 mixes the color registers. So we need an array of munged
* indices in order to access the correct reg.
*/
static int MV300_reg_1bit[2] = {
0, 1
};
static int MV300_reg_4bit[16] = {
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
};
static int MV300_reg_8bit[256] = {
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
};
static int *MV300_reg = MV300_reg_8bit;
#endif /* ATAFB_EXT */
static int inverse;
extern int fontheight_8x8;
extern int fontwidth_8x8;
extern unsigned char fontdata_8x8[];
extern int fontheight_8x16;
extern int fontwidth_8x16;
extern unsigned char fontdata_8x16[];
/*
* struct fb_ops {
* * open/release and usage marking
* struct module *owner;
* int (*fb_open)(struct fb_info *info, int user);
* int (*fb_release)(struct fb_info *info, int user);
*
* * For framebuffers with strange non linear layouts or that do not
* * work with normal memory mapped access
* ssize_t (*fb_read)(struct file *file, char __user *buf, size_t count, loff_t *ppos);
* ssize_t (*fb_write)(struct file *file, const char __user *buf, size_t count, loff_t *ppos);
*
* * checks var and eventually tweaks it to something supported,
* * DOES NOT MODIFY PAR *
* int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
*
* * set the video mode according to info->var *
* int (*fb_set_par)(struct fb_info *info);
*
* * set color register *
* int (*fb_setcolreg)(unsigned int regno, unsigned int red, unsigned int green,
* unsigned int blue, unsigned int transp, struct fb_info *info);
*
* * set color registers in batch *
* int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
*
* * blank display *
* int (*fb_blank)(int blank, struct fb_info *info);
*
* * pan display *
* int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
*
* *** The meat of the drawing engine ***
* * Draws a rectangle *
* void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
* * Copy data from area to another *
* void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
* * Draws a image to the display *
* void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
*
* * Draws cursor *
* int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
*
* * Rotates the display *
* void (*fb_rotate)(struct fb_info *info, int angle);
*
* * wait for blit idle, optional *
* int (*fb_sync)(struct fb_info *info);
*
* * perform fb specific ioctl (optional) *
* int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
* unsigned long arg);
*
* * Handle 32bit compat ioctl (optional) *
* int (*fb_compat_ioctl)(struct fb_info *info, unsigned int cmd,
* unsigned long arg);
*
* * perform fb specific mmap *
* int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
* } ;
*/
/* ++roman: This structure abstracts from the underlying hardware (ST(e),
* TT, or Falcon.
*
* int (*detect)(void)
* This function should detect the current video mode settings and
* store them in atafb_predefined[0] for later reference by the
* user. Return the index+1 of an equivalent predefined mode or 0
* if there is no such.
*
* int (*encode_fix)(struct fb_fix_screeninfo *fix,
* struct atafb_par *par)
* This function should fill in the 'fix' structure based on the
* values in the 'par' structure.
* !!! Obsolete, perhaps !!!
*
* int (*decode_var)(struct fb_var_screeninfo *var,
* struct atafb_par *par)
* Get the video params out of 'var'. If a value doesn't fit, round
* it up, if it's too big, return EINVAL.
* Round up in the following order: bits_per_pixel, xres, yres,
* xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
* horizontal timing, vertical timing.
*
* int (*encode_var)(struct fb_var_screeninfo *var,
* struct atafb_par *par);
* Fill the 'var' structure based on the values in 'par' and maybe
* other values read out of the hardware.
*
* void (*get_par)(struct atafb_par *par)
* Fill the hardware's 'par' structure.
* !!! Used only by detect() !!!
*
* void (*set_par)(struct atafb_par *par)
* Set the hardware according to 'par'.
*
* void (*set_screen_base)(void *s_base)
* Set the base address of the displayed frame buffer. Only called
* if yres_virtual > yres or xres_virtual > xres.
*
* int (*blank)(int blank_mode)
* Blank the screen if blank_mode != 0, else unblank. If blank == NULL then
* the caller blanks by setting the CLUT to all black. Return 0 if blanking
* succeeded, !=0 if un-/blanking failed due to e.g. a video mode which
* doesn't support it. Implements VESA suspend and powerdown modes on
* hardware that supports disabling hsync/vsync:
* blank_mode == 2: suspend vsync, 3:suspend hsync, 4: powerdown.
*/
static struct fb_hwswitch {
int (*detect)(void);
int (*encode_fix)(struct fb_fix_screeninfo *fix,
struct atafb_par *par);
int (*decode_var)(struct fb_var_screeninfo *var,
struct atafb_par *par);
int (*encode_var)(struct fb_var_screeninfo *var,
struct atafb_par *par);
void (*get_par)(struct atafb_par *par);
void (*set_par)(struct atafb_par *par);
void (*set_screen_base)(void *s_base);
int (*blank)(int blank_mode);
int (*pan_display)(struct fb_var_screeninfo *var,
struct fb_info *info);
} *fbhw;
static char *autodetect_names[] = { "autodetect", NULL };
static char *stlow_names[] = { "stlow", NULL };
static char *stmid_names[] = { "stmid", "default5", NULL };
static char *sthigh_names[] = { "sthigh", "default4", NULL };
static char *ttlow_names[] = { "ttlow", NULL };
static char *ttmid_names[] = { "ttmid", "default1", NULL };
static char *tthigh_names[] = { "tthigh", "default2", NULL };
static char *vga2_names[] = { "vga2", NULL };
static char *vga4_names[] = { "vga4", NULL };
static char *vga16_names[] = { "vga16", "default3", NULL };
static char *vga256_names[] = { "vga256", NULL };
static char *falh2_names[] = { "falh2", NULL };
static char *falh16_names[] = { "falh16", NULL };
static char **fb_var_names[] = {
autodetect_names,
stlow_names,
stmid_names,
sthigh_names,
ttlow_names,
ttmid_names,
tthigh_names,
vga2_names,
vga4_names,
vga16_names,
vga256_names,
falh2_names,
falh16_names,
NULL
};
static struct fb_var_screeninfo atafb_predefined[] = {
/*
* yres_virtual == 0 means use hw-scrolling if possible, else yres
*/
{ /* autodetect */
0, 0, 0, 0, 0, 0, 0, 0, /* xres-grayscale */
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, /* red green blue tran*/
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* st low */
320, 200, 320, 0, 0, 0, 4, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* st mid */
640, 200, 640, 0, 0, 0, 2, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* st high */
640, 400, 640, 0, 0, 0, 1, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* tt low */
320, 480, 320, 0, 0, 0, 8, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* tt mid */
640, 480, 640, 0, 0, 0, 4, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* tt high */
1280, 960, 1280, 0, 0, 0, 1, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* vga2 */
640, 480, 640, 0, 0, 0, 1, 0,
{0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* vga4 */
640, 480, 640, 0, 0, 0, 2, 0,
{0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* vga16 */
640, 480, 640, 0, 0, 0, 4, 0,
{0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* vga256 */
640, 480, 640, 0, 0, 0, 8, 0,
{0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* falh2 */
896, 608, 896, 0, 0, 0, 1, 0,
{0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ /* falh16 */
896, 608, 896, 0, 0, 0, 4, 0,
{0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
};
static int num_atafb_predefined = ARRAY_SIZE(atafb_predefined);
static struct fb_videomode atafb_modedb[] __initdata = {
/*
* Atari Video Modes
*
* If you change these, make sure to update DEFMODE_* as well!
*/
/*
* ST/TT Video Modes
*/
{
/* 320x200, 15 kHz, 60 Hz (ST low) */
"st-low", 60, 320, 200, 32000, 32, 16, 31, 14, 96, 4,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 640x200, 15 kHz, 60 Hz (ST medium) */
"st-mid", 60, 640, 200, 32000, 32, 16, 31, 14, 96, 4,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 640x400, 30.25 kHz, 63.5 Hz (ST high) */
"st-high", 63, 640, 400, 32000, 128, 0, 40, 14, 128, 4,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 320x480, 15 kHz, 60 Hz (TT low) */
"tt-low", 60, 320, 480, 31041, 120, 100, 8, 16, 140, 30,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 640x480, 29 kHz, 57 Hz (TT medium) */
"tt-mid", 60, 640, 480, 31041, 120, 100, 8, 16, 140, 30,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 1280x960, 29 kHz, 60 Hz (TT high) */
"tt-high", 57, 640, 960, 31041, 120, 100, 8, 16, 140, 30,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
},
/*
* VGA Video Modes
*/
{
/* 640x480, 31 kHz, 60 Hz (VGA) */
"vga", 63.5, 640, 480, 32000, 18, 42, 31, 11, 96, 3,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
}, {
/* 640x400, 31 kHz, 70 Hz (VGA) */
"vga70", 70, 640, 400, 32000, 18, 42, 31, 11, 96, 3,
FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
},
/*
* Falcon HiRes Video Modes
*/
{
/* 896x608, 31 kHz, 60 Hz (Falcon High) */
"falh", 60, 896, 608, 32000, 18, 42, 31, 1, 96,3,
0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
},
};
#define NUM_TOTAL_MODES ARRAY_SIZE(atafb_modedb)
static char *mode_option __initdata = NULL;
/* default modes */
#define DEFMODE_TT 5 /* "tt-high" for TT */
#define DEFMODE_F30 7 /* "vga70" for Falcon */
#define DEFMODE_STE 2 /* "st-high" for ST/E */
#define DEFMODE_EXT 6 /* "vga" for external */
static int get_video_mode(char *vname)
{
char ***name_list;
char **name;
int i;
name_list = fb_var_names;
for (i = 0; i < num_atafb_predefined; i++) {
name = *name_list++;
if (!name || !*name)
break;
while (*name) {
if (!strcmp(vname, *name))
return i + 1;
name++;
}
}
return 0;
}
/* ------------------- TT specific functions ---------------------- */
#ifdef ATAFB_TT
static int tt_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
{
int mode;
strcpy(fix->id, "Atari Builtin");
fix->smem_start = (unsigned long)real_screen_base;
fix->smem_len = screen_len;
fix->type = FB_TYPE_INTERLEAVED_PLANES;
fix->type_aux = 2;
fix->visual = FB_VISUAL_PSEUDOCOLOR;
mode = par->hw.tt.mode & TT_SHIFTER_MODEMASK;
if (mode == TT_SHIFTER_TTHIGH || mode == TT_SHIFTER_STHIGH) {
fix->type = FB_TYPE_PACKED_PIXELS;
fix->type_aux = 0;
if (mode == TT_SHIFTER_TTHIGH)
fix->visual = FB_VISUAL_MONO01;
}
fix->xpanstep = 0;
fix->ypanstep = 1;
fix->ywrapstep = 0;
fix->line_length = par->next_line;
fix->accel = FB_ACCEL_ATARIBLITT;
return 0;
}
static int tt_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
{
int xres = var->xres;
int yres = var->yres;
int bpp = var->bits_per_pixel;
int linelen;
int yres_virtual = var->yres_virtual;
if (mono_moni) {
if (bpp > 1 || xres > sttt_xres * 2 || yres > tt_yres * 2)
return -EINVAL;
par->hw.tt.mode = TT_SHIFTER_TTHIGH;
xres = sttt_xres * 2;
yres = tt_yres * 2;
bpp = 1;
} else {
if (bpp > 8 || xres > sttt_xres || yres > tt_yres)
return -EINVAL;
if (bpp > 4) {
if (xres > sttt_xres / 2 || yres > tt_yres)
return -EINVAL;
par->hw.tt.mode = TT_SHIFTER_TTLOW;
xres = sttt_xres / 2;
yres = tt_yres;
bpp = 8;
} else if (bpp > 2) {
if (xres > sttt_xres || yres > tt_yres)
return -EINVAL;
if (xres > sttt_xres / 2 || yres > st_yres / 2) {
par->hw.tt.mode = TT_SHIFTER_TTMID;
xres = sttt_xres;
yres = tt_yres;
bpp = 4;
} else {
par->hw.tt.mode = TT_SHIFTER_STLOW;
xres = sttt_xres / 2;
yres = st_yres / 2;
bpp = 4;
}
} else if (bpp > 1) {
if (xres > sttt_xres || yres > st_yres / 2)
return -EINVAL;
par->hw.tt.mode = TT_SHIFTER_STMID;
xres = sttt_xres;
yres = st_yres / 2;
bpp = 2;
} else if (var->xres > sttt_xres || var->yres > st_yres) {
return -EINVAL;
} else {
par->hw.tt.mode = TT_SHIFTER_STHIGH;
xres = sttt_xres;
yres = st_yres;
bpp = 1;
}
}
if (yres_virtual <= 0)
yres_virtual = 0;
else if (yres_virtual < yres)
yres_virtual = yres;
if (var->sync & FB_SYNC_EXT)
par->hw.tt.sync = 0;
else
par->hw.tt.sync = 1;
linelen = xres * bpp / 8;
if (yres_virtual * linelen > screen_len && screen_len)
return -EINVAL;
if (yres * linelen > screen_len && screen_len)
return -EINVAL;
if (var->yoffset + yres > yres_virtual && yres_virtual)
return -EINVAL;
par->yres_virtual = yres_virtual;
par->screen_base = screen_base + var->yoffset * linelen;
par->next_line = linelen;
return 0;
}
static int tt_encode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
{
int linelen;
memset(var, 0, sizeof(struct fb_var_screeninfo));
var->red.offset = 0;
var->red.length = 4;
var->red.msb_right = 0;
var->grayscale = 0;
var->pixclock = 31041;
var->left_margin = 120; /* these may be incorrect */
var->right_margin = 100;
var->upper_margin = 8;
var->lower_margin = 16;
var->hsync_len = 140;
var->vsync_len = 30;
var->height = -1;
var->width = -1;
if (par->hw.tt.sync & 1)
var->sync = 0;
else
var->sync = FB_SYNC_EXT;
switch (par->hw.tt.mode & TT_SHIFTER_MODEMASK) {
case TT_SHIFTER_STLOW:
var->xres = sttt_xres / 2;
var->xres_virtual = sttt_xres_virtual / 2;
var->yres = st_yres / 2;
var->bits_per_pixel = 4;
break;
case TT_SHIFTER_STMID:
var->xres = sttt_xres;
var->xres_virtual = sttt_xres_virtual;
var->yres = st_yres / 2;
var->bits_per_pixel = 2;
break;
case TT_SHIFTER_STHIGH:
var->xres = sttt_xres;
var->xres_virtual = sttt_xres_virtual;
var->yres = st_yres;
var->bits_per_pixel = 1;
break;
case TT_SHIFTER_TTLOW:
var->xres = sttt_xres / 2;
var->xres_virtual = sttt_xres_virtual / 2;
var->yres = tt_yres;
var->bits_per_pixel = 8;
break;
case TT_SHIFTER_TTMID:
var->xres = sttt_xres;
var->xres_virtual = sttt_xres_virtual;
var->yres = tt_yres;
var->bits_per_pixel = 4;
break;
case TT_SHIFTER_TTHIGH:
var->red.length = 0;
var->xres = sttt_xres * 2;
var->xres_virtual = sttt_xres_virtual * 2;
var->yres = tt_yres * 2;
var->bits_per_pixel = 1;
break;
}
var->blue = var->green = var->red;
var->transp.offset = 0;
var->transp.length = 0;
var->transp.msb_right = 0;
linelen = var->xres_virtual * var->bits_per_pixel / 8;
if (!use_hwscroll)
var->yres_virtual = var->yres;
else if (screen_len) {
if (par->yres_virtual)
var->yres_virtual = par->yres_virtual;
else
/* yres_virtual == 0 means use maximum */
var->yres_virtual = screen_len / linelen;
} else {
if (hwscroll < 0)
var->yres_virtual = 2 * var->yres;
else
var->yres_virtual = var->yres + hwscroll * 16;
}
var->xoffset = 0;
if (screen_base)
var->yoffset = (par->screen_base - screen_base) / linelen;
else
var->yoffset = 0;
var->nonstd = 0;
var->activate = 0;
var->vmode = FB_VMODE_NONINTERLACED;
return 0;
}
static void tt_get_par(struct atafb_par *par)
{
unsigned long addr;
par->hw.tt.mode = shifter_tt.tt_shiftmode;
par->hw.tt.sync = shifter.syncmode;
addr = ((shifter.bas_hi & 0xff) << 16) |
((shifter.bas_md & 0xff) << 8) |
((shifter.bas_lo & 0xff));
par->screen_base = phys_to_virt(addr);
}
static void tt_set_par(struct atafb_par *par)
{
shifter_tt.tt_shiftmode = par->hw.tt.mode;
shifter.syncmode = par->hw.tt.sync;
/* only set screen_base if really necessary */
if (current_par.screen_base != par->screen_base)
fbhw->set_screen_base(par->screen_base);
}
static int tt_setcolreg(unsigned int regno, unsigned int red,
unsigned int green, unsigned int blue,
unsigned int transp, struct fb_info *info)
{
if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
regno += 254;
if (regno > 255)
return 1;
tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) |
(blue >> 12));
if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) ==
TT_SHIFTER_STHIGH && regno == 254)
tt_palette[0] = 0;
return 0;
}
static int tt_detect(void)
{
struct atafb_par par;
/* Determine the connected monitor: The DMA sound must be
* disabled before reading the MFP GPIP, because the Sound
* Done Signal and the Monochrome Detect are XORed together!
*
* Even on a TT, we should look if there is a DMA sound. It was
* announced that the Eagle is TT compatible, but only the PCM is
* missing...
*/
if (ATARIHW_PRESENT(PCM_8BIT)) {
tt_dmasnd.ctrl = DMASND_CTRL_OFF;
udelay(20); /* wait a while for things to settle down */
}
mono_moni = (st_mfp.par_dt_reg & 0x80) == 0;
tt_get_par(&par);
tt_encode_var(&atafb_predefined[0], &par);
return 1;
}
#endif /* ATAFB_TT */
/* ------------------- Falcon specific functions ---------------------- */
#ifdef ATAFB_FALCON
static int mon_type; /* Falcon connected monitor */
static int f030_bus_width; /* Falcon ram bus width (for vid_control) */
#define F_MON_SM 0
#define F_MON_SC 1
#define F_MON_VGA 2
#define F_MON_TV 3
static struct pixel_clock {
unsigned long f; /* f/[Hz] */
unsigned long t; /* t/[ps] (=1/f) */
int right, hsync, left; /* standard timing in clock cycles, not pixel */
/* hsync initialized in falcon_detect() */
int sync_mask; /* or-mask for hw.falcon.sync to set this clock */
int control_mask; /* ditto, for hw.falcon.vid_control */
} f25 = {
25175000, 39721, 18, 0, 42, 0x0, VCO_CLOCK25
}, f32 = {
32000000, 31250, 18, 0, 42, 0x0, 0
}, fext = {
0, 0, 18, 0, 42, 0x1, 0
};
/* VIDEL-prescale values [mon_type][pixel_length from VCO] */
static int vdl_prescale[4][3] = {
{ 4,2,1 }, { 4,2,1 }, { 4,2,2 }, { 4,2,1 }
};
/* Default hsync timing [mon_type] in picoseconds */
static long h_syncs[4] = { 3000000, 4875000, 4000000, 4875000 };
static inline int hxx_prescale(struct falcon_hw *hw)
{
return hw->ste_mode ? 16
: vdl_prescale[mon_type][hw->vid_mode >> 2 & 0x3];
}
static int falcon_encode_fix(struct fb_fix_screeninfo *fix,
struct atafb_par *par)
{
strcpy(fix->id, "Atari Builtin");
fix->smem_start = (unsigned long)real_screen_base;
fix->smem_len = screen_len;
fix->type = FB_TYPE_INTERLEAVED_PLANES;
fix->type_aux = 2;
fix->visual = FB_VISUAL_PSEUDOCOLOR;
fix->xpanstep = 1;
fix->ypanstep = 1;
fix->ywrapstep = 0;
if (par->hw.falcon.mono) {
fix->type = FB_TYPE_PACKED_PIXELS;
fix->type_aux = 0;
/* no smooth scrolling with longword aligned video mem */
fix->xpanstep = 32;
} else if (par->hw.falcon.f_shift & 0x100) {
fix->type = FB_TYPE_PACKED_PIXELS;
fix->type_aux = 0;
/* Is this ok or should it be DIRECTCOLOR? */
fix->visual = FB_VISUAL_TRUECOLOR;
fix->xpanstep = 2;
}
fix->line_length = par->next_line;
fix->accel = FB_ACCEL_ATARIBLITT;
return 0;
}
static int falcon_decode_var(struct fb_var_screeninfo *var,
struct atafb_par *par)
{
int bpp = var->bits_per_pixel;
int xres = var->xres;
int yres = var->yres;
int xres_virtual = var->xres_virtual;
int yres_virtual = var->yres_virtual;
int left_margin, right_margin, hsync_len;
int upper_margin, lower_margin, vsync_len;
int linelen;
int interlace = 0, doubleline = 0;
struct pixel_clock *pclock;
int plen; /* width of pixel in clock cycles */
int xstretch;
int prescale;
int longoffset = 0;
int hfreq, vfreq;
int hdb_off, hde_off, base_off;
int gstart, gend1, gend2, align;
/*
Get the video params out of 'var'. If a value doesn't fit, round
it up, if it's too big, return EINVAL.
Round up in the following order: bits_per_pixel, xres, yres,
xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
horizontal timing, vertical timing.
There is a maximum of screen resolution determined by pixelclock
and minimum frame rate -- (X+hmarg.)*(Y+vmarg.)*vfmin <= pixelclock.
In interlace mode this is " * " *vfmin <= pixelclock.
Additional constraints: hfreq.
Frequency range for multisync monitors is given via command line.
For TV and SM124 both frequencies are fixed.
X % 16 == 0 to fit 8x?? font (except 1 bitplane modes must use X%32 == 0)
Y % 16 == 0 to fit 8x16 font
Y % 8 == 0 if Y<400
Currently interlace and doubleline mode in var are ignored.
On SM124 and TV only the standard resolutions can be used.
*/
/* Reject uninitialized mode */
if (!xres || !yres || !bpp)
return -EINVAL;
if (mon_type == F_MON_SM && bpp != 1)
return -EINVAL;
if (bpp <= 1) {
bpp = 1;
par->hw.falcon.f_shift = 0x400;
par->hw.falcon.st_shift = 0x200;
} else if (bpp <= 2) {
bpp = 2;
par->hw.falcon.f_shift = 0x000;
par->hw.falcon.st_shift = 0x100;
} else if (bpp <= 4) {
bpp = 4;
par->hw.falcon.f_shift = 0x000;
par->hw.falcon.st_shift = 0x000;
} else if (bpp <= 8) {
bpp = 8;
par->hw.falcon.f_shift = 0x010;
} else if (bpp <= 16) {
bpp = 16; /* packed pixel mode */
par->hw.falcon.f_shift = 0x100; /* hicolor, no overlay */
} else
return -EINVAL;
par->hw.falcon.bpp = bpp;
if (mon_type == F_MON_SM || DontCalcRes) {
/* Skip all calculations. VGA/TV/SC1224 only supported. */
struct fb_var_screeninfo *myvar = &atafb_predefined[0];
if (bpp > myvar->bits_per_pixel ||
var->xres > myvar->xres ||
var->yres > myvar->yres)
return -EINVAL;
fbhw->get_par(par); /* Current par will be new par */
goto set_screen_base; /* Don't forget this */
}
/* Only some fixed resolutions < 640x400 */