2 * linux/drivers/video/macmodes.c -- Standard MacOS video modes
4 * Copyright (C) 1998 Geert Uytterhoeven
6 * 2000 - Removal of OpenFirmware dependencies by:
8 * - Brad Douglas <brad@neruo.com>
10 * 2001 - Documented with DocBook
11 * - Brad Douglas <brad@neruo.com>
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file COPYING in the main directory of this archive for
18 #include <linux/errno.h>
20 #include <linux/string.h>
21 #include <linux/module.h>
26 * MacOS video mode definitions
28 * Order IS important! If you change these, don't forget to update
32 #define DEFAULT_MODEDB_INDEX 0
34 static const struct fb_videomode mac_modedb
[] = {
36 /* 512x384, 60Hz, Non-Interlaced (15.67 MHz dot clock) */
37 "mac2", 60, 512, 384, 63828, 80, 16, 19, 1, 32, 3,
38 0, FB_VMODE_NONINTERLACED
40 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
41 "mac5", 60, 640, 480, 39722, 32, 32, 33, 10, 96, 2,
42 0, FB_VMODE_NONINTERLACED
44 /* 640x480, 67Hz, Non-Interlaced (30.0 MHz dotclock) */
45 "mac6", 67, 640, 480, 33334, 80, 80, 39, 3, 64, 3,
46 0, FB_VMODE_NONINTERLACED
48 /* 640x870, 75Hz (portrait), Non-Interlaced (57.28 MHz dot clock) */
49 "mac7", 75, 640, 870, 17457, 80, 32, 42, 3, 80, 3,
50 0, FB_VMODE_NONINTERLACED
52 /* 800x600, 56 Hz, Non-Interlaced (36.00 MHz dotclock) */
53 "mac9", 56, 800, 600, 27778, 112, 40, 22, 1, 72, 2,
54 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
56 /* 800x600, 60 Hz, Non-Interlaced (40.00 MHz dotclock) */
57 "mac10", 60, 800, 600, 25000, 72, 56, 23, 1, 128, 4,
58 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
60 /* 800x600, 72 Hz, Non-Interlaced (50.00 MHz dotclock) */
61 "mac11", 72, 800, 600, 20000, 48, 72, 23, 37, 120, 6,
62 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
64 /* 800x600, 75 Hz, Non-Interlaced (49.50 MHz dotclock) */
65 "mac12", 75, 800, 600, 20203, 144, 32, 21, 1, 80, 3,
66 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
68 /* 832x624, 75Hz, Non-Interlaced (57.6 MHz dotclock) */
69 "mac13", 75, 832, 624, 17362, 208, 48, 39, 1, 64, 3,
70 0, FB_VMODE_NONINTERLACED
72 /* 1024x768, 60 Hz, Non-Interlaced (65.00 MHz dotclock) */
73 "mac14", 60, 1024, 768, 15385, 144, 40, 29, 3, 136, 6,
74 0, FB_VMODE_NONINTERLACED
76 /* 1024x768, 72 Hz, Non-Interlaced (75.00 MHz dotclock) */
77 "mac15", 72, 1024, 768, 13334, 128, 40, 29, 3, 136, 6,
78 0, FB_VMODE_NONINTERLACED
80 /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
81 "mac16", 75, 1024, 768, 12699, 176, 16, 28, 1, 96, 3,
82 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
84 /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
85 "mac17", 75, 1024, 768, 12699, 160, 32, 28, 1, 96, 3,
86 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
88 /* 1152x870, 75 Hz, Non-Interlaced (100.0 MHz dotclock) */
89 "mac18", 75, 1152, 870, 10000, 128, 48, 39, 3, 128, 3,
90 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
92 /* 1280x960, 75 Hz, Non-Interlaced (126.00 MHz dotclock) */
93 "mac19", 75, 1280, 960, 7937, 224, 32, 36, 1, 144, 3,
94 0, FB_VMODE_NONINTERLACED
96 /* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */
97 "mac20", 75, 1280, 1024, 7408, 232, 64, 38, 1, 112, 3,
98 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
100 /* 1152x768, 60 Hz, Titanium PowerBook */
101 "mac21", 60, 1152, 768, 15386, 158, 26, 29, 3, 136, 6,
102 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
104 /* 1600x1024, 60 Hz, Non-Interlaced (112.27 MHz dotclock) */
105 "mac22", 60, 1600, 1024, 8908, 88, 104, 1, 10, 16, 1,
106 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
113 * Mapping between MacOS video mode numbers and video mode definitions
115 * These MUST be ordered in
116 * - increasing resolution
117 * - decreasing pixel clock period
120 static const struct mode_map
{
122 const struct fb_videomode
*mode
;
125 { VMODE_512_384_60
, &mac_modedb
[0] },
127 { VMODE_640_480_60
, &mac_modedb
[1] },
128 { VMODE_640_480_67
, &mac_modedb
[2] },
130 { VMODE_640_870_75P
, &mac_modedb
[3] },
132 { VMODE_800_600_56
, &mac_modedb
[4] },
133 { VMODE_800_600_60
, &mac_modedb
[5] },
134 { VMODE_800_600_75
, &mac_modedb
[7] },
135 { VMODE_800_600_72
, &mac_modedb
[6] },
137 { VMODE_832_624_75
, &mac_modedb
[8] },
139 { VMODE_1024_768_60
, &mac_modedb
[9] },
140 { VMODE_1024_768_70
, &mac_modedb
[10] },
141 { VMODE_1024_768_75V
, &mac_modedb
[11] },
142 { VMODE_1024_768_75
, &mac_modedb
[12] },
144 { VMODE_1152_768_60
, &mac_modedb
[16] },
146 { VMODE_1152_870_75
, &mac_modedb
[13] },
148 { VMODE_1280_960_75
, &mac_modedb
[14] },
150 { VMODE_1280_1024_75
, &mac_modedb
[15] },
152 { VMODE_1600_1024_60
, &mac_modedb
[17] },
158 * Mapping between monitor sense values and MacOS video mode numbers
161 static const struct monitor_map
{
165 { 0x000, VMODE_1280_1024_75
}, /* 21" RGB */
166 { 0x114, VMODE_640_870_75P
}, /* Portrait Monochrome */
167 { 0x221, VMODE_512_384_60
}, /* 12" RGB*/
168 { 0x331, VMODE_1280_1024_75
}, /* 21" RGB (Radius) */
169 { 0x334, VMODE_1280_1024_75
}, /* 21" mono (Radius) */
170 { 0x335, VMODE_1280_1024_75
}, /* 21" mono */
171 { 0x40A, VMODE_640_480_60I
}, /* NTSC */
172 { 0x51E, VMODE_640_870_75P
}, /* Portrait RGB */
173 { 0x603, VMODE_832_624_75
}, /* 12"-16" multiscan */
174 { 0x60b, VMODE_1024_768_70
}, /* 13"-19" multiscan */
175 { 0x623, VMODE_1152_870_75
}, /* 13"-21" multiscan */
176 { 0x62b, VMODE_640_480_67
}, /* 13"/14" RGB */
177 { 0x700, VMODE_640_480_50I
}, /* PAL */
178 { 0x714, VMODE_640_480_60I
}, /* NTSC */
179 { 0x717, VMODE_800_600_75
}, /* VGA */
180 { 0x72d, VMODE_832_624_75
}, /* 16" RGB (Goldfish) */
181 { 0x730, VMODE_768_576_50I
}, /* PAL (Alternate) */
182 { 0x73a, VMODE_1152_870_75
}, /* 3rd party 19" */
183 { 0x73f, VMODE_640_480_67
}, /* no sense lines connected at all */
184 { 0xBEEF, VMODE_1600_1024_60
}, /* 22" Apple Cinema Display */
185 { -1, VMODE_640_480_60
}, /* catch-all, must be last */
189 * mac_vmode_to_var - converts vmode/cmode pair to var structure
190 * @vmode: MacOS video mode
191 * @cmode: MacOS color mode
192 * @var: frame buffer video mode structure
194 * Converts a MacOS vmode/cmode pair to a frame buffer video
197 * Returns negative errno on error, or zero for success.
201 int mac_vmode_to_var(int vmode
, int cmode
, struct fb_var_screeninfo
*var
)
203 const struct fb_videomode
*mode
= NULL
;
204 const struct mode_map
*map
;
206 for (map
= mac_modes
; map
->vmode
!= -1; map
++)
207 if (map
->vmode
== vmode
) {
214 memset(var
, 0, sizeof(struct fb_var_screeninfo
));
217 var
->bits_per_pixel
= 8;
220 var
->green
.offset
= 0;
221 var
->green
.length
= 8;
222 var
->blue
.offset
= 0;
223 var
->blue
.length
= 8;
227 var
->bits_per_pixel
= 16;
228 var
->red
.offset
= 10;
230 var
->green
.offset
= 5;
231 var
->green
.length
= 5;
232 var
->blue
.offset
= 0;
233 var
->blue
.length
= 5;
237 var
->bits_per_pixel
= 32;
238 var
->red
.offset
= 16;
240 var
->green
.offset
= 8;
241 var
->green
.length
= 8;
242 var
->blue
.offset
= 0;
243 var
->blue
.length
= 8;
244 var
->transp
.offset
= 24;
245 var
->transp
.length
= 8;
251 var
->xres
= mode
->xres
;
252 var
->yres
= mode
->yres
;
253 var
->xres_virtual
= mode
->xres
;
254 var
->yres_virtual
= mode
->yres
;
257 var
->pixclock
= mode
->pixclock
;
258 var
->left_margin
= mode
->left_margin
;
259 var
->right_margin
= mode
->right_margin
;
260 var
->upper_margin
= mode
->upper_margin
;
261 var
->lower_margin
= mode
->lower_margin
;
262 var
->hsync_len
= mode
->hsync_len
;
263 var
->vsync_len
= mode
->vsync_len
;
264 var
->sync
= mode
->sync
;
265 var
->vmode
= mode
->vmode
;
268 EXPORT_SYMBOL(mac_vmode_to_var
);
271 * mac_var_to_vmode - convert var structure to MacOS vmode/cmode pair
272 * @var: frame buffer video mode structure
273 * @vmode: MacOS video mode
274 * @cmode: MacOS color mode
276 * Converts a frame buffer video mode structure to a MacOS
279 * Returns negative errno on error, or zero for success.
283 int mac_var_to_vmode(const struct fb_var_screeninfo
*var
, int *vmode
,
286 const struct mode_map
*map
;
288 if (var
->bits_per_pixel
<= 8)
290 else if (var
->bits_per_pixel
<= 16)
292 else if (var
->bits_per_pixel
<= 32)
298 * Find the mac_mode with a matching resolution or failing that, the
299 * closest larger resolution. Skip modes with a shorter pixel clock period.
301 for (map
= mac_modes
; map
->vmode
!= -1; map
++) {
302 const struct fb_videomode
*mode
= map
->mode
;
304 if (var
->xres
> mode
->xres
|| var
->yres
> mode
->yres
)
306 if (var
->xres_virtual
> mode
->xres
|| var
->yres_virtual
> mode
->yres
)
308 if (var
->pixclock
> mode
->pixclock
)
310 if ((var
->vmode
& FB_VMODE_MASK
) != mode
->vmode
)
315 * Having found a good resolution, find the matching pixel clock
316 * or failing that, the closest longer pixel clock period.
319 while (map
->vmode
!= -1) {
320 const struct fb_videomode
*clk_mode
= map
->mode
;
322 if (mode
->xres
!= clk_mode
->xres
|| mode
->yres
!= clk_mode
->yres
)
324 if (var
->pixclock
> mode
->pixclock
)
326 if (mode
->vmode
!= clk_mode
->vmode
)
337 * mac_map_monitor_sense - Convert monitor sense to vmode
338 * @sense: Macintosh monitor sense number
340 * Converts a Macintosh monitor sense number to a MacOS
343 * Returns MacOS vmode video mode number.
347 int mac_map_monitor_sense(int sense
)
349 const struct monitor_map
*map
;
351 for (map
= mac_monitors
; map
->sense
!= -1; map
++)
352 if (map
->sense
== sense
)
356 EXPORT_SYMBOL(mac_map_monitor_sense
);
359 * mac_find_mode - find a video mode
360 * @var: frame buffer user defined part of display
361 * @info: frame buffer info structure
362 * @mode_option: video mode name (see mac_modedb[])
363 * @default_bpp: default color depth in bits per pixel
365 * Finds a suitable video mode. Tries to set mode specified
366 * by @mode_option. If the name of the wanted mode begins with
367 * 'mac', the Mac video mode database will be used, otherwise it
368 * will fall back to the standard video mode database.
370 * Note: Function marked as __init and can only be used during
373 * Returns error code from fb_find_mode (see fb_find_mode
378 int mac_find_mode(struct fb_var_screeninfo
*var
, struct fb_info
*info
,
379 const char *mode_option
, unsigned int default_bpp
)
381 const struct fb_videomode
*db
= NULL
;
382 unsigned int dbsize
= 0;
384 if (mode_option
&& !strncmp(mode_option
, "mac", 3)) {
387 dbsize
= ARRAY_SIZE(mac_modedb
);
389 return fb_find_mode(var
, info
, mode_option
, db
, dbsize
,
390 &mac_modedb
[DEFAULT_MODEDB_INDEX
], default_bpp
);
392 EXPORT_SYMBOL(mac_find_mode
);
394 MODULE_LICENSE("GPL");