macmodes.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. * 2001 - Documented with DocBook
  11. * - Brad Douglas <brad@neruo.com>
  12. *
  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
  15. * more details.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/export.h>
  19. #include <linux/fb.h>
  20. #include <linux/string.h>
  21. #include <linux/module.h>
  22. #include "macmodes.h"
  23. /*
  24. * MacOS video mode definitions
  25. *
  26. * Order IS important! If you change these, don't forget to update
  27. * mac_modes[] below!
  28. */
  29. #define DEFAULT_MODEDB_INDEX 0
  30. static const struct fb_videomode mac_modedb[] = {
  31. {
  32. /* 512x384, 60Hz, Non-Interlaced (15.67 MHz dot clock) */
  33. "mac2", 60, 512, 384, 63828, 80, 16, 19, 1, 32, 3,
  34. 0, FB_VMODE_NONINTERLACED
  35. }, {
  36. /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
  37. "mac5", 60, 640, 480, 39722, 32, 32, 33, 10, 96, 2,
  38. 0, FB_VMODE_NONINTERLACED
  39. }, {
  40. /* 640x480, 67Hz, Non-Interlaced (30.0 MHz dotclock) */
  41. "mac6", 67, 640, 480, 33334, 80, 80, 39, 3, 64, 3,
  42. 0, FB_VMODE_NONINTERLACED
  43. }, {
  44. /* 640x870, 75Hz (portrait), Non-Interlaced (57.28 MHz dot clock) */
  45. "mac7", 75, 640, 870, 17457, 80, 32, 42, 3, 80, 3,
  46. 0, FB_VMODE_NONINTERLACED
  47. }, {
  48. /* 800x600, 56 Hz, Non-Interlaced (36.00 MHz dotclock) */
  49. "mac9", 56, 800, 600, 27778, 112, 40, 22, 1, 72, 2,
  50. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  51. }, {
  52. /* 800x600, 60 Hz, Non-Interlaced (40.00 MHz dotclock) */
  53. "mac10", 60, 800, 600, 25000, 72, 56, 23, 1, 128, 4,
  54. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  55. }, {
  56. /* 800x600, 72 Hz, Non-Interlaced (50.00 MHz dotclock) */
  57. "mac11", 72, 800, 600, 20000, 48, 72, 23, 37, 120, 6,
  58. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  59. }, {
  60. /* 800x600, 75 Hz, Non-Interlaced (49.50 MHz dotclock) */
  61. "mac12", 75, 800, 600, 20203, 144, 32, 21, 1, 80, 3,
  62. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  63. }, {
  64. /* 832x624, 75Hz, Non-Interlaced (57.6 MHz dotclock) */
  65. "mac13", 75, 832, 624, 17362, 208, 48, 39, 1, 64, 3,
  66. 0, FB_VMODE_NONINTERLACED
  67. }, {
  68. /* 1024x768, 60 Hz, Non-Interlaced (65.00 MHz dotclock) */
  69. "mac14", 60, 1024, 768, 15385, 144, 40, 29, 3, 136, 6,
  70. 0, FB_VMODE_NONINTERLACED
  71. }, {
  72. /* 1024x768, 72 Hz, Non-Interlaced (75.00 MHz dotclock) */
  73. "mac15", 72, 1024, 768, 13334, 128, 40, 29, 3, 136, 6,
  74. 0, FB_VMODE_NONINTERLACED
  75. }, {
  76. /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
  77. "mac16", 75, 1024, 768, 12699, 176, 16, 28, 1, 96, 3,
  78. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  79. }, {
  80. /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
  81. "mac17", 75, 1024, 768, 12699, 160, 32, 28, 1, 96, 3,
  82. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  83. }, {
  84. /* 1152x870, 75 Hz, Non-Interlaced (100.0 MHz dotclock) */
  85. "mac18", 75, 1152, 870, 10000, 128, 48, 39, 3, 128, 3,
  86. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  87. }, {
  88. /* 1280x960, 75 Hz, Non-Interlaced (126.00 MHz dotclock) */
  89. "mac19", 75, 1280, 960, 7937, 224, 32, 36, 1, 144, 3,
  90. 0, FB_VMODE_NONINTERLACED
  91. }, {
  92. /* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */
  93. "mac20", 75, 1280, 1024, 7408, 232, 64, 38, 1, 112, 3,
  94. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  95. }, {
  96. /* 1152x768, 60 Hz, Titanium PowerBook */
  97. "mac21", 60, 1152, 768, 15386, 158, 26, 29, 3, 136, 6,
  98. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  99. }, {
  100. /* 1600x1024, 60 Hz, Non-Interlaced (112.27 MHz dotclock) */
  101. "mac22", 60, 1600, 1024, 8908, 88, 104, 1, 10, 16, 1,
  102. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  103. }
  104. #if 0
  105. /* Anyone who has timings for these? */
  106. {
  107. /* VMODE_512_384_60I: 512x384, 60Hz, Interlaced (NTSC) */
  108. "mac1", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen,
  109. sync, FB_VMODE_INTERLACED
  110. }, {
  111. /* VMODE_640_480_50I: 640x480, 50Hz, Interlaced (PAL) */
  112. "mac3", 50, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
  113. sync, FB_VMODE_INTERLACED
  114. }, {
  115. /* VMODE_640_480_60I: 640x480, 60Hz, Interlaced (NTSC) */
  116. "mac4", 60, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
  117. sync, FB_VMODE_INTERLACED
  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. * Mapping between MacOS video mode numbers and video mode definitions
  127. *
  128. * These MUST be ordered in
  129. * - increasing resolution
  130. * - decreasing pixel clock period
  131. */
  132. static const struct mode_map {
  133. int vmode;
  134. const struct fb_videomode *mode;
  135. } mac_modes[] = {
  136. /* 512x384 */
  137. { VMODE_512_384_60, &mac_modedb[0] },
  138. /* 640x480 */
  139. { VMODE_640_480_60, &mac_modedb[1] },
  140. { VMODE_640_480_67, &mac_modedb[2] },
  141. /* 640x870 */
  142. { VMODE_640_870_75P, &mac_modedb[3] },
  143. /* 800x600 */
  144. { VMODE_800_600_56, &mac_modedb[4] },
  145. { VMODE_800_600_60, &mac_modedb[5] },
  146. { VMODE_800_600_75, &mac_modedb[7] },
  147. { VMODE_800_600_72, &mac_modedb[6] },
  148. /* 832x624 */
  149. { VMODE_832_624_75, &mac_modedb[8] },
  150. /* 1024x768 */
  151. { VMODE_1024_768_60, &mac_modedb[9] },
  152. { VMODE_1024_768_70, &mac_modedb[10] },
  153. { VMODE_1024_768_75V, &mac_modedb[11] },
  154. { VMODE_1024_768_75, &mac_modedb[12] },
  155. /* 1152x768 */
  156. { VMODE_1152_768_60, &mac_modedb[16] },
  157. /* 1152x870 */
  158. { VMODE_1152_870_75, &mac_modedb[13] },
  159. /* 1280x960 */
  160. { VMODE_1280_960_75, &mac_modedb[14] },
  161. /* 1280x1024 */
  162. { VMODE_1280_1024_75, &mac_modedb[15] },
  163. /* 1600x1024 */
  164. { VMODE_1600_1024_60, &mac_modedb[17] },
  165. { -1, NULL }
  166. };
  167. /*
  168. * Mapping between monitor sense values and MacOS video mode numbers
  169. */
  170. static const struct monitor_map {
  171. int sense;
  172. int vmode;
  173. } mac_monitors[] = {
  174. { 0x000, VMODE_1280_1024_75 }, /* 21" RGB */
  175. { 0x114, VMODE_640_870_75P }, /* Portrait Monochrome */
  176. { 0x221, VMODE_512_384_60 }, /* 12" RGB*/
  177. { 0x331, VMODE_1280_1024_75 }, /* 21" RGB (Radius) */
  178. { 0x334, VMODE_1280_1024_75 }, /* 21" mono (Radius) */
  179. { 0x335, VMODE_1280_1024_75 }, /* 21" mono */
  180. { 0x40A, VMODE_640_480_60I }, /* NTSC */
  181. { 0x51E, VMODE_640_870_75P }, /* Portrait RGB */
  182. { 0x603, VMODE_832_624_75 }, /* 12"-16" multiscan */
  183. { 0x60b, VMODE_1024_768_70 }, /* 13"-19" multiscan */
  184. { 0x623, VMODE_1152_870_75 }, /* 13"-21" multiscan */
  185. { 0x62b, VMODE_640_480_67 }, /* 13"/14" RGB */
  186. { 0x700, VMODE_640_480_50I }, /* PAL */
  187. { 0x714, VMODE_640_480_60I }, /* NTSC */
  188. { 0x717, VMODE_800_600_75 }, /* VGA */
  189. { 0x72d, VMODE_832_624_75 }, /* 16" RGB (Goldfish) */
  190. { 0x730, VMODE_768_576_50I }, /* PAL (Alternate) */
  191. { 0x73a, VMODE_1152_870_75 }, /* 3rd party 19" */
  192. { 0x73f, VMODE_640_480_67 }, /* no sense lines connected at all */
  193. { 0xBEEF, VMODE_1600_1024_60 }, /* 22" Apple Cinema Display */
  194. { -1, VMODE_640_480_60 }, /* catch-all, must be last */
  195. };
  196. /**
  197. * mac_vmode_to_var - converts vmode/cmode pair to var structure
  198. * @vmode: MacOS video mode
  199. * @cmode: MacOS color mode
  200. * @var: frame buffer video mode structure
  201. *
  202. * Converts a MacOS vmode/cmode pair to a frame buffer video
  203. * mode structure.
  204. *
  205. * Returns negative errno on error, or zero for success.
  206. *
  207. */
  208. int mac_vmode_to_var(int vmode, int cmode, struct fb_var_screeninfo *var)
  209. {
  210. const struct fb_videomode *mode = NULL;
  211. const struct mode_map *map;
  212. for (map = mac_modes; map->vmode != -1; map++)
  213. if (map->vmode == vmode) {
  214. mode = map->mode;
  215. break;
  216. }
  217. if (!mode)
  218. return -EINVAL;
  219. memset(var, 0, sizeof(struct fb_var_screeninfo));
  220. switch (cmode) {
  221. case CMODE_8:
  222. var->bits_per_pixel = 8;
  223. var->red.offset = 0;
  224. var->red.length = 8;
  225. var->green.offset = 0;
  226. var->green.length = 8;
  227. var->blue.offset = 0;
  228. var->blue.length = 8;
  229. break;
  230. case CMODE_16:
  231. var->bits_per_pixel = 16;
  232. var->red.offset = 10;
  233. var->red.length = 5;
  234. var->green.offset = 5;
  235. var->green.length = 5;
  236. var->blue.offset = 0;
  237. var->blue.length = 5;
  238. break;
  239. case CMODE_32:
  240. var->bits_per_pixel = 32;
  241. var->red.offset = 16;
  242. var->red.length = 8;
  243. var->green.offset = 8;
  244. var->green.length = 8;
  245. var->blue.offset = 0;
  246. var->blue.length = 8;
  247. var->transp.offset = 24;
  248. var->transp.length = 8;
  249. break;
  250. default:
  251. return -EINVAL;
  252. }
  253. var->xres = mode->xres;
  254. var->yres = mode->yres;
  255. var->xres_virtual = mode->xres;
  256. var->yres_virtual = mode->yres;
  257. var->height = -1;
  258. var->width = -1;
  259. var->pixclock = mode->pixclock;
  260. var->left_margin = mode->left_margin;
  261. var->right_margin = mode->right_margin;
  262. var->upper_margin = mode->upper_margin;
  263. var->lower_margin = mode->lower_margin;
  264. var->hsync_len = mode->hsync_len;
  265. var->vsync_len = mode->vsync_len;
  266. var->sync = mode->sync;
  267. var->vmode = mode->vmode;
  268. return 0;
  269. }
  270. EXPORT_SYMBOL(mac_vmode_to_var);
  271. /**
  272. * mac_var_to_vmode - convert var structure to MacOS vmode/cmode pair
  273. * @var: frame buffer video mode structure
  274. * @vmode: MacOS video mode
  275. * @cmode: MacOS color mode
  276. *
  277. * Converts a frame buffer video mode structure to a MacOS
  278. * vmode/cmode pair.
  279. *
  280. * Returns negative errno on error, or zero for success.
  281. *
  282. */
  283. int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode,
  284. int *cmode)
  285. {
  286. const struct mode_map *map;
  287. if (var->bits_per_pixel <= 8)
  288. *cmode = CMODE_8;
  289. else if (var->bits_per_pixel <= 16)
  290. *cmode = CMODE_16;
  291. else if (var->bits_per_pixel <= 32)
  292. *cmode = CMODE_32;
  293. else
  294. return -EINVAL;
  295. /*
  296. * Find the mac_mode with a matching resolution or failing that, the
  297. * closest larger resolution. Skip modes with a shorter pixel clock period.
  298. */
  299. for (map = mac_modes; map->vmode != -1; map++) {
  300. const struct fb_videomode *mode = map->mode;
  301. if (var->xres > mode->xres || var->yres > mode->yres)
  302. continue;
  303. if (var->xres_virtual > mode->xres || var->yres_virtual > mode->yres)
  304. continue;
  305. if (var->pixclock > mode->pixclock)
  306. continue;
  307. if ((var->vmode & FB_VMODE_MASK) != mode->vmode)
  308. continue;
  309. *vmode = map->vmode;
  310. /*
  311. * Having found a good resolution, find the matching pixel clock
  312. * or failing that, the closest longer pixel clock period.
  313. */
  314. map++;
  315. while (map->vmode != -1) {
  316. const struct fb_videomode *clk_mode = map->mode;
  317. if (mode->xres != clk_mode->xres || mode->yres != clk_mode->yres)
  318. break;
  319. if (var->pixclock > mode->pixclock)
  320. break;
  321. if (mode->vmode != clk_mode->vmode)
  322. continue;
  323. *vmode = map->vmode;
  324. map++;
  325. }
  326. return 0;
  327. }
  328. return -EINVAL;
  329. }
  330. /**
  331. * mac_map_monitor_sense - Convert monitor sense to vmode
  332. * @sense: Macintosh monitor sense number
  333. *
  334. * Converts a Macintosh monitor sense number to a MacOS
  335. * vmode number.
  336. *
  337. * Returns MacOS vmode video mode number.
  338. *
  339. */
  340. int mac_map_monitor_sense(int sense)
  341. {
  342. const struct monitor_map *map;
  343. for (map = mac_monitors; map->sense != -1; map++)
  344. if (map->sense == sense)
  345. break;
  346. return map->vmode;
  347. }
  348. EXPORT_SYMBOL(mac_map_monitor_sense);
  349. /**
  350. * mac_find_mode - find a video mode
  351. * @var: frame buffer user defined part of display
  352. * @info: frame buffer info structure
  353. * @mode_option: video mode name (see mac_modedb[])
  354. * @default_bpp: default color depth in bits per pixel
  355. *
  356. * Finds a suitable video mode. Tries to set mode specified
  357. * by @mode_option. If the name of the wanted mode begins with
  358. * 'mac', the Mac video mode database will be used, otherwise it
  359. * will fall back to the standard video mode database.
  360. *
  361. * Note: Function marked as __init and can only be used during
  362. * system boot.
  363. *
  364. * Returns error code from fb_find_mode (see fb_find_mode
  365. * function).
  366. *
  367. */
  368. int mac_find_mode(struct fb_var_screeninfo *var, struct fb_info *info,
  369. const char *mode_option, unsigned int default_bpp)
  370. {
  371. const struct fb_videomode *db = NULL;
  372. unsigned int dbsize = 0;
  373. if (mode_option && !strncmp(mode_option, "mac", 3)) {
  374. mode_option += 3;
  375. db = mac_modedb;
  376. dbsize = ARRAY_SIZE(mac_modedb);
  377. }
  378. return fb_find_mode(var, info, mode_option, db, dbsize,
  379. &mac_modedb[DEFAULT_MODEDB_INDEX], default_bpp);
  380. }
  381. EXPORT_SYMBOL(mac_find_mode);
  382. MODULE_DESCRIPTION("MacOS video mode library");
  383. MODULE_LICENSE("GPL");