1 /*
2 * linux/drivers/video/macmodes.c -- Standard MacOS video modes
3 *
4 * Copyright (C) 1998 Geert Uytterhoeven
5 *
6 * 2000 - Removal of OpenFirmware dependencies by:
7 * - Ani Joshi
8 * - Brad Douglas <brad@neruo.com>
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
12 * more details.
13 */
14
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/fb.h>
18 #include <linux/string.h>
19
20 #ifdef CONFIG_FB_COMPAT_XPMAC
21 #include <asm/vc_ioctl.h>
22 #endif
23
24 #include <video/fbcon.h>
25 #include <video/macmodes.h>
26
27
28 /*
29 * MacOS video mode definitions
30 *
31 * Order IS important! If you change these, don't forget to update
32 * mac_modes[] below!
33 */
34
35 #define DEFAULT_MODEDB_INDEX 0
36
37 static const struct fb_videomode mac_modedb[] = {
38 {
39 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
40 "mac5", 60, 640, 480, 39722, 32, 32, 33, 10, 96, 2,
41 0, FB_VMODE_NONINTERLACED
42 }, {
43 /* 640x480, 67Hz, Non-Interlaced (30.0 MHz dotclock) */
44 "mac6", 67, 640, 480, 33334, 80, 80, 39, 3, 64, 3,
45 0, FB_VMODE_NONINTERLACED
46 }, {
47 /* 800x600, 56 Hz, Non-Interlaced (36.00 MHz dotclock) */
48 "mac9", 56, 800, 600, 27778, 112, 40, 22, 1, 72, 2,
49 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
50 }, {
51 /* 800x600, 60 Hz, Non-Interlaced (40.00 MHz dotclock) */
52 "mac10", 60, 800, 600, 25000, 72, 56, 23, 1, 128, 4,
53 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
54 }, {
55 /* 800x600, 72 Hz, Non-Interlaced (50.00 MHz dotclock) */
56 "mac11", 72, 800, 600, 20000, 48, 72, 23, 37, 120, 6,
57 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
58 }, {
59 /* 800x600, 75 Hz, Non-Interlaced (49.50 MHz dotclock) */
60 "mac12", 75, 800, 600, 20203, 144, 32, 21, 1, 80, 3,
61 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
62 }, {
63 /* 832x624, 75Hz, Non-Interlaced (57.6 MHz dotclock) */
64 "mac13", 75, 832, 624, 17362, 208, 48, 39, 1, 64, 3,
65 0, FB_VMODE_NONINTERLACED
66 }, {
67 /* 1024x768, 60 Hz, Non-Interlaced (65.00 MHz dotclock) */
68 "mac14", 60, 1024, 768, 15385, 144, 40, 29, 3, 136, 6,
69 0, FB_VMODE_NONINTERLACED
70 }, {
71 /* 1024x768, 72 Hz, Non-Interlaced (75.00 MHz dotclock) */
72 "mac15", 72, 1024, 768, 13334, 128, 40, 29, 3, 136, 6,
73 0, FB_VMODE_NONINTERLACED
74 }, {
75 /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
76 "mac16", 75, 1024, 768, 12699, 176, 16, 28, 1, 96, 3,
77 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
78 }, {
79 /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
80 "mac17", 75, 1024, 768, 12699, 160, 32, 28, 1, 96, 3,
81 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
82 }, {
83 /* 1152x870, 75 Hz, Non-Interlaced (100.0 MHz dotclock) */
84 "mac18", 75, 1152, 870, 10000, 128, 48, 39, 3, 128, 3,
85 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
86 }, {
87 /* 1280x960, 75 Hz, Non-Interlaced (126.00 MHz dotclock) */
88 "mac19", 75, 1280, 960, 7937, 224, 32, 36, 1, 144, 3,
89 0, FB_VMODE_NONINTERLACED
90 }, {
91 /* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */
92 "mac20", 75, 1280, 1024, 7408, 232, 64, 38, 1, 112, 3,
93 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
94 },
95
96 #if 0
97 /* Anyone who has timings for these? */
98 {
99 /* VMODE_512_384_60I: 512x384, 60Hz, Interlaced (NTSC) */
100 "mac1", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen,
101 sync, FB_VMODE_INTERLACED
102 }, {
103 /* VMODE_512_384_60: 512x384, 60Hz, Non-Interlaced */
104 "mac2", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen,
105 sync, FB_VMODE_NONINTERLACED
106 }, {
107 /* VMODE_640_480_50I: 640x480, 50Hz, Interlaced (PAL) */
108 "mac3", 50, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
109 sync, FB_VMODE_INTERLACED
110 }, {
111 /* VMODE_640_480_60I: 640x480, 60Hz, Interlaced (NTSC) */
112 "mac4", 60, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
113 sync, FB_VMODE_INTERLACED
114 }, {
115 /* VMODE_640_870_75P: 640x870, 75Hz (portrait), Non-Interlaced */
116 "mac7", 75, 640, 870, pixclock, left, right, upper, lower, hslen, vslen,
117 sync, FB_VMODE_NONINTERLACED
118 }, {
119 /* VMODE_768_576_50I: 768x576, 50Hz (PAL full frame), Interlaced */
120 "mac8", 50, 768, 576, pixclock, left, right, upper, lower, hslen, vslen,
121 sync, FB_VMODE_INTERLACED
122 },
123 #endif
124 };
125
126
127 /*
128 * Mapping between MacOS video mode numbers and video mode definitions
129 *
130 * These MUST be ordered in
131 * - increasing resolution
132 * - decreasing refresh rate
133 */
134
135 static const struct mode_map {
136 int vmode;
137 const struct fb_videomode *mode;
138 } mac_modes[] = {
139 /* 640x480 */
140 { VMODE_640_480_67, &mac_modedb[1] },
141 { VMODE_640_480_60, &mac_modedb[0] },
142 /* 800x600 */
143 { VMODE_800_600_75, &mac_modedb[5] },
144 { VMODE_800_600_72, &mac_modedb[4] },
145 { VMODE_800_600_60, &mac_modedb[3] },
146 { VMODE_800_600_56, &mac_modedb[2] },
147 /* 832x624 */
148 { VMODE_832_624_75, &mac_modedb[6] },
149 /* 1024x768 */
150 { VMODE_1024_768_75, &mac_modedb[10] },
151 { VMODE_1024_768_75V, &mac_modedb[9] },
152 { VMODE_1024_768_70, &mac_modedb[8] },
153 { VMODE_1024_768_60, &mac_modedb[7] },
154 /* 1152x870 */
155 { VMODE_1152_870_75, &mac_modedb[11] },
156 /* 1280x960 */
157 { VMODE_1280_960_75, &mac_modedb[12] },
158 /* 1280x1024 */
159 { VMODE_1280_1024_75, &mac_modedb[13] },
160 { -1, NULL }
161 };
162
163
164 /*
165 * Mapping between monitor sense values and MacOS video mode numbers
166 */
167
168 static const struct monitor_map {
169 int sense;
170 int vmode;
171 } mac_monitors[] = {
172 { 0x000, VMODE_1280_1024_75 }, /* 21" RGB */
173 { 0x114, VMODE_640_870_75P }, /* Portrait Monochrome */
174 { 0x221, VMODE_512_384_60 }, /* 12" RGB*/
175 { 0x331, VMODE_1280_1024_75 }, /* 21" RGB (Radius) */
176 { 0x334, VMODE_1280_1024_75 }, /* 21" mono (Radius) */
177 { 0x335, VMODE_1280_1024_75 }, /* 21" mono */
178 { 0x40A, VMODE_640_480_60I }, /* NTSC */
179 { 0x51E, VMODE_640_870_75P }, /* Portrait RGB */
180 { 0x603, VMODE_832_624_75 }, /* 12"-16" multiscan */
181 { 0x60b, VMODE_1024_768_70 }, /* 13"-19" multiscan */
182 { 0x623, VMODE_1152_870_75 }, /* 13"-21" multiscan */
183 { 0x62b, VMODE_640_480_67 }, /* 13"/14" RGB */
184 { 0x700, VMODE_640_480_50I }, /* PAL */
185 { 0x714, VMODE_640_480_60I }, /* NTSC */
186 { 0x717, VMODE_800_600_75 }, /* VGA */
187 { 0x72d, VMODE_832_624_75 }, /* 16" RGB (Goldfish) */
188 { 0x730, VMODE_768_576_50I }, /* PAL (Alternate) */
189 { 0x73a, VMODE_1152_870_75 }, /* 3rd party 19" */
190 { 0x73f, VMODE_640_480_67 }, /* no sense lines connected at all */
191 { -1, VMODE_640_480_60 }, /* catch-all, must be last */
192 };
193
194 #ifdef CONFIG_FB_COMPAT_XPMAC
195 struct fb_info *console_fb_info = NULL;
196 struct vc_mode display_info;
197
198 static u16 palette_red[16];
199 static u16 palette_green[16];
200 static u16 palette_blue[16];
201 static struct fb_cmap palette_cmap = {
202 0, 16, palette_red, palette_green, palette_blue, NULL
203 };
204
205
206 int console_getmode(struct vc_mode *mode)
207 {
208 *mode = display_info;
209 return 0;
210 }
211
212 int console_setmode(struct vc_mode *mode, int doit)
213 {
214 struct fb_var_screeninfo var;
215 int cmode, err;
216
217 if (!console_fb_info)
218 return -EOPNOTSUPP;
219
220 switch(mode->depth) {
221 case 0:
222 case 8:
223 cmode = CMODE_8;
224 break;
225 case 16:
226 cmode = CMODE_16;
227 break;
228 case 24:
229 case 32:
230 cmode = CMODE_32;
231 break;
232 default:
233 return -EINVAL;
234 }
235
236 if ((err = mac_vmode_to_var(mode->mode, cmode, &var)))
237 return err;
238
239 var.activate = FB_ACTIVATE_TEST;
240 err = console_fb_info->fbops->fb_set_var(&var, fg_console,
241 console_fb_info);
242 if (err || !doit)
243 return err;
244 else {
245 int unit;
246
247 var.activate = FB_ACTIVATE_NOW;
248 for (unit = 0; unit < MAX_NR_CONSOLES; unit++)
249 if (fb_display[unit].conp &&
250 (GET_FB_IDX(console_fb_info->node) == con2fb_map[unit]))
251 console_fb_info->fbops->fb_set_var(&var, unit,
252 console_fb_info);
253 }
254
255 return 0;
256 }
257
258 int console_setcmap(int n_entries, unsigned char *red, unsigned char *green,
259 unsigned char *blue)
260 {
261 int i, j, n = 0, err;
262
263 if (!console_fb_info)
264 return -EOPNOTSUPP;
265
266 for (i = 0; i < n_entries; i += n) {
267 n = n_entries - i;
268 if (n > 16)
269 n = 16;
270 palette_cmap.start = i;
271 palette_cmap.len = n;
272
273 for (j = 0; j < n; j++) {
274 palette_cmap.red[j] = (red[i+j] << 8) | red[i+j];
275 palette_cmap.green[j] = (green[i+j] << 8) | green[i+j];
276 palette_cmap.blue[j] = (blue[i+j] << 8) | blue[i+j];
277 }
278 err = console_fb_info->fbops->fb_set_cmap(&palette_cmap, 1,
279 fg_console,
280 console_fb_info);
281 if (err)
282 return err;
283 }
284
285 return 0;
286 }
287
288 int console_powermode(int mode)
289 {
290 if (mode == VC_POWERMODE_INQUIRY)
291 return 0;
292 if (mode < VESA_NO_BLANKING || mode > VESA_POWERDOWN)
293 return -EINVAL;
294 /* Not Supported */
295 return -ENXIO;
296 }
297 #endif /* CONFIG_FB_COMPAT_XPMAC */
298
299
300 /*
301 * Convert a MacOS vmode/cmode pair to a frame buffer video mode structure
302 */
303
304 int mac_vmode_to_var(int vmode, int cmode, struct fb_var_screeninfo *var)
305 {
306 const struct fb_videomode *mode = NULL;
307 const struct mode_map *map;
308
309 for (map = mac_modes; map->vmode != -1; map++)
310 if (map->vmode == vmode) {
311 mode = map->mode;
312 break;
313 }
314 if (!mode)
315 return -EINVAL;
316
317 memset(var, 0, sizeof(struct fb_var_screeninfo));
318 switch (cmode) {
319 case CMODE_8:
320 var->bits_per_pixel = 8;
321 var->red.offset = 0;
322 var->red.length = 8;
323 var->green.offset = 0;
324 var->green.length = 8;
325 var->blue.offset = 0;
326 var->blue.length = 8;
327 break;
328
329 case CMODE_16:
330 var->bits_per_pixel = 16;
331 var->red.offset = 10;
332 var->red.length = 5;
333 var->green.offset = 5;
334 var->green.length = 5;
335 var->blue.offset = 0;
336 var->blue.length = 5;
337 break;
338
339 case CMODE_32:
340 var->bits_per_pixel = 32;
341 var->red.offset = 16;
342 var->red.length = 8;
343 var->green.offset = 8;
344 var->green.length = 8;
345 var->blue.offset = 0;
346 var->blue.length = 8;
347 var->transp.offset = 24;
348 var->transp.length = 8;
349 break;
350
351 default:
352 return -EINVAL;
353 }
354 var->xres = mode->xres;
355 var->yres = mode->yres;
356 var->xres_virtual = mode->xres;
357 var->yres_virtual = mode->yres;
358 var->height = -1;
359 var->width = -1;
360 var->pixclock = mode->pixclock;
361 var->left_margin = mode->left_margin;
362 var->right_margin = mode->right_margin;
363 var->upper_margin = mode->upper_margin;
364 var->lower_margin = mode->lower_margin;
365 var->hsync_len = mode->hsync_len;
366 var->vsync_len = mode->vsync_len;
367 var->sync = mode->sync;
368 var->vmode = mode->vmode;
369 return 0;
370 }
371
372
373 /*
374 * Convert a frame buffer video mode structure to a MacOS vmode/cmode pair
375 */
376
377 int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode,
378 int *cmode)
379 {
380 const struct fb_videomode *mode = NULL;
381 const struct mode_map *map;
382
383 if (var->bits_per_pixel <= 8)
384 *cmode = CMODE_8;
385 else if (var->bits_per_pixel <= 16)
386 *cmode = CMODE_16;
387 else if (var->bits_per_pixel <= 32)
388 *cmode = CMODE_32;
389 else
390 return -EINVAL;
391
392 for (map = mac_modes; map->vmode != -1; map++) {
393 mode = map->mode;
394 if (var->xres > mode->xres || var->yres > mode->yres)
395 continue;
396 if (var->xres_virtual > mode->xres || var->yres_virtual > mode->yres)
397 continue;
398 if (var->pixclock > mode->pixclock)
399 continue;
400 if ((var->vmode & FB_VMODE_MASK) != mode->vmode)
401 continue;
402 *vmode = map->vmode;
403 return 0;
404 }
405 return -EINVAL;
406 }
407
408
409 /*
410 * Convert a Mac monitor sense number to a MacOS vmode number
411 */
412
413 int mac_map_monitor_sense(int sense)
414 {
415 const struct monitor_map *map;
416
417 for (map = mac_monitors; map->sense != -1; map++)
418 if (map->sense == sense)
419 break;
420 return map->vmode;
421 }
422
423
424 /*
425 * Find a suitable video mode
426 *
427 * If the name of the wanted mode begins with `mac', use the Mac video
428 * mode database, else fall back to the standard video mode database.
429 */
430
431 int __init mac_find_mode(struct fb_var_screeninfo *var, struct fb_info *info,
432 const char *mode_option, unsigned int default_bpp)
433 {
434 const struct fb_videomode *db = NULL;
435 unsigned int dbsize = 0;
436
437 if (mode_option && !strncmp(mode_option, "mac", 3)) {
438 db = mac_modedb;
439 dbsize = sizeof(mac_modedb)/sizeof(*mac_modedb);
440 }
441 return fb_find_mode(var, info, mode_option, db, dbsize,
442 &mac_modedb[DEFAULT_MODEDB_INDEX], default_bpp);
443 }
444
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.