macmodes.c 12 KB

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