acornfb.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. /*
  2. * linux/drivers/video/acornfb.c
  3. *
  4. * Copyright (C) 1998-2001 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Frame buffer code for Acorn platforms
  11. *
  12. * NOTE: Most of the modes with X!=640 will disappear shortly.
  13. * NOTE: Startup setting of HS & VS polarity not supported.
  14. * (do we need to support it if we're coming up in 640x480?)
  15. *
  16. * FIXME: (things broken by the "new improved" FBCON API)
  17. * - Blanking 8bpp displays with VIDC
  18. */
  19. #include <linux/config.h>
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/ctype.h>
  25. #include <linux/slab.h>
  26. #include <linux/init.h>
  27. #include <linux/fb.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/dma-mapping.h>
  30. #include <asm/hardware.h>
  31. #include <asm/io.h>
  32. #include <asm/irq.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/pgtable.h>
  35. #include "acornfb.h"
  36. /*
  37. * VIDC machines can't do 16 or 32BPP modes.
  38. */
  39. #ifdef HAS_VIDC
  40. #undef FBCON_HAS_CFB16
  41. #undef FBCON_HAS_CFB32
  42. #endif
  43. /*
  44. * Default resolution.
  45. * NOTE that it has to be supported in the table towards
  46. * the end of this file.
  47. */
  48. #define DEFAULT_XRES 640
  49. #define DEFAULT_YRES 480
  50. #define DEFAULT_BPP 4
  51. /*
  52. * define this to debug the video mode selection
  53. */
  54. #undef DEBUG_MODE_SELECTION
  55. /*
  56. * Translation from RISC OS monitor types to actual
  57. * HSYNC and VSYNC frequency ranges. These are
  58. * probably not right, but they're the best info I
  59. * have. Allow 1% either way on the nominal for TVs.
  60. */
  61. #define NR_MONTYPES 6
  62. static struct fb_monspecs monspecs[NR_MONTYPES] __initdata = {
  63. { /* TV */
  64. .hfmin = 15469,
  65. .hfmax = 15781,
  66. .vfmin = 49,
  67. .vfmax = 51,
  68. }, { /* Multi Freq */
  69. .hfmin = 0,
  70. .hfmax = 99999,
  71. .vfmin = 0,
  72. .vfmax = 199,
  73. }, { /* Hi-res mono */
  74. .hfmin = 58608,
  75. .hfmax = 58608,
  76. .vfmin = 64,
  77. .vfmax = 64,
  78. }, { /* VGA */
  79. .hfmin = 30000,
  80. .hfmax = 70000,
  81. .vfmin = 60,
  82. .vfmax = 60,
  83. }, { /* SVGA */
  84. .hfmin = 30000,
  85. .hfmax = 70000,
  86. .vfmin = 56,
  87. .vfmax = 75,
  88. }, {
  89. .hfmin = 30000,
  90. .hfmax = 70000,
  91. .vfmin = 60,
  92. .vfmax = 60,
  93. }
  94. };
  95. static struct fb_info fb_info;
  96. static struct acornfb_par current_par;
  97. static struct vidc_timing current_vidc;
  98. extern unsigned int vram_size; /* set by setup.c */
  99. #ifdef HAS_VIDC
  100. #define MAX_SIZE 480*1024
  101. /* CTL VIDC Actual
  102. * 24.000 0 8.000
  103. * 25.175 0 8.392
  104. * 36.000 0 12.000
  105. * 24.000 1 12.000
  106. * 25.175 1 12.588
  107. * 24.000 2 16.000
  108. * 25.175 2 16.783
  109. * 36.000 1 18.000
  110. * 24.000 3 24.000
  111. * 36.000 2 24.000
  112. * 25.175 3 25.175
  113. * 36.000 3 36.000
  114. */
  115. struct pixclock {
  116. u_long min_clock;
  117. u_long max_clock;
  118. u_int vidc_ctl;
  119. u_int vid_ctl;
  120. };
  121. static struct pixclock arc_clocks[] = {
  122. /* we allow +/-1% on these */
  123. { 123750, 126250, VIDC_CTRL_DIV3, VID_CTL_24MHz }, /* 8.000MHz */
  124. { 82500, 84167, VIDC_CTRL_DIV2, VID_CTL_24MHz }, /* 12.000MHz */
  125. { 61875, 63125, VIDC_CTRL_DIV1_5, VID_CTL_24MHz }, /* 16.000MHz */
  126. { 41250, 42083, VIDC_CTRL_DIV1, VID_CTL_24MHz }, /* 24.000MHz */
  127. };
  128. #ifdef CONFIG_ARCH_A5K
  129. static struct pixclock a5k_clocks[] = {
  130. { 117974, 120357, VIDC_CTRL_DIV3, VID_CTL_25MHz }, /* 8.392MHz */
  131. { 78649, 80238, VIDC_CTRL_DIV2, VID_CTL_25MHz }, /* 12.588MHz */
  132. { 58987, 60178, VIDC_CTRL_DIV1_5, VID_CTL_25MHz }, /* 16.588MHz */
  133. { 55000, 56111, VIDC_CTRL_DIV2, VID_CTL_36MHz }, /* 18.000MHz */
  134. { 39325, 40119, VIDC_CTRL_DIV1, VID_CTL_25MHz }, /* 25.175MHz */
  135. { 27500, 28055, VIDC_CTRL_DIV1, VID_CTL_36MHz }, /* 36.000MHz */
  136. };
  137. #endif
  138. static struct pixclock *
  139. acornfb_valid_pixrate(struct fb_var_screeninfo *var)
  140. {
  141. u_long pixclock = var->pixclock;
  142. u_int i;
  143. if (!var->pixclock)
  144. return NULL;
  145. for (i = 0; i < ARRAY_SIZE(arc_clocks); i++)
  146. if (pixclock > arc_clocks[i].min_clock &&
  147. pixclock < arc_clocks[i].max_clock)
  148. return arc_clocks + i;
  149. #ifdef CONFIG_ARCH_A5K
  150. if (machine_is_a5k()) {
  151. for (i = 0; i < ARRAY_SIZE(a5k_clocks); i++)
  152. if (pixclock > a5k_clocks[i].min_clock &&
  153. pixclock < a5k_clocks[i].max_clock)
  154. return a5k_clocks + i;
  155. }
  156. #endif
  157. return NULL;
  158. }
  159. /* VIDC Rules:
  160. * hcr : must be even (interlace, hcr/2 must be even)
  161. * hswr : must be even
  162. * hdsr : must be odd
  163. * hder : must be odd
  164. *
  165. * vcr : must be odd
  166. * vswr : >= 1
  167. * vdsr : >= 1
  168. * vder : >= vdsr
  169. * if interlaced, then hcr/2 must be even
  170. */
  171. static void
  172. acornfb_set_timing(struct fb_var_screeninfo *var)
  173. {
  174. struct pixclock *pclk;
  175. struct vidc_timing vidc;
  176. u_int horiz_correction;
  177. u_int sync_len, display_start, display_end, cycle;
  178. u_int is_interlaced;
  179. u_int vid_ctl, vidc_ctl;
  180. u_int bandwidth;
  181. memset(&vidc, 0, sizeof(vidc));
  182. pclk = acornfb_valid_pixrate(var);
  183. vidc_ctl = pclk->vidc_ctl;
  184. vid_ctl = pclk->vid_ctl;
  185. bandwidth = var->pixclock * 8 / var->bits_per_pixel;
  186. /* 25.175, 4bpp = 79.444ns per byte, 317.776ns per word: fifo = 2,6 */
  187. if (bandwidth > 143500)
  188. vidc_ctl |= VIDC_CTRL_FIFO_3_7;
  189. else if (bandwidth > 71750)
  190. vidc_ctl |= VIDC_CTRL_FIFO_2_6;
  191. else if (bandwidth > 35875)
  192. vidc_ctl |= VIDC_CTRL_FIFO_1_5;
  193. else
  194. vidc_ctl |= VIDC_CTRL_FIFO_0_4;
  195. switch (var->bits_per_pixel) {
  196. case 1:
  197. horiz_correction = 19;
  198. vidc_ctl |= VIDC_CTRL_1BPP;
  199. break;
  200. case 2:
  201. horiz_correction = 11;
  202. vidc_ctl |= VIDC_CTRL_2BPP;
  203. break;
  204. case 4:
  205. horiz_correction = 7;
  206. vidc_ctl |= VIDC_CTRL_4BPP;
  207. break;
  208. default:
  209. case 8:
  210. horiz_correction = 5;
  211. vidc_ctl |= VIDC_CTRL_8BPP;
  212. break;
  213. }
  214. if (var->sync & FB_SYNC_COMP_HIGH_ACT) /* should be FB_SYNC_COMP */
  215. vidc_ctl |= VIDC_CTRL_CSYNC;
  216. else {
  217. if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
  218. vid_ctl |= VID_CTL_HS_NHSYNC;
  219. if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
  220. vid_ctl |= VID_CTL_VS_NVSYNC;
  221. }
  222. sync_len = var->hsync_len;
  223. display_start = sync_len + var->left_margin;
  224. display_end = display_start + var->xres;
  225. cycle = display_end + var->right_margin;
  226. /* if interlaced, then hcr/2 must be even */
  227. is_interlaced = (var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED;
  228. if (is_interlaced) {
  229. vidc_ctl |= VIDC_CTRL_INTERLACE;
  230. if (cycle & 2) {
  231. cycle += 2;
  232. var->right_margin += 2;
  233. }
  234. }
  235. vidc.h_cycle = (cycle - 2) / 2;
  236. vidc.h_sync_width = (sync_len - 2) / 2;
  237. vidc.h_border_start = (display_start - 1) / 2;
  238. vidc.h_display_start = (display_start - horiz_correction) / 2;
  239. vidc.h_display_end = (display_end - horiz_correction) / 2;
  240. vidc.h_border_end = (display_end - 1) / 2;
  241. vidc.h_interlace = (vidc.h_cycle + 1) / 2;
  242. sync_len = var->vsync_len;
  243. display_start = sync_len + var->upper_margin;
  244. display_end = display_start + var->yres;
  245. cycle = display_end + var->lower_margin;
  246. if (is_interlaced)
  247. cycle = (cycle - 3) / 2;
  248. else
  249. cycle = cycle - 1;
  250. vidc.v_cycle = cycle;
  251. vidc.v_sync_width = sync_len - 1;
  252. vidc.v_border_start = display_start - 1;
  253. vidc.v_display_start = vidc.v_border_start;
  254. vidc.v_display_end = display_end - 1;
  255. vidc.v_border_end = vidc.v_display_end;
  256. if (machine_is_a5k())
  257. __raw_writeb(vid_ctl, IOEB_VID_CTL);
  258. if (memcmp(&current_vidc, &vidc, sizeof(vidc))) {
  259. current_vidc = vidc;
  260. vidc_writel(0xe0000000 | vidc_ctl);
  261. vidc_writel(0x80000000 | (vidc.h_cycle << 14));
  262. vidc_writel(0x84000000 | (vidc.h_sync_width << 14));
  263. vidc_writel(0x88000000 | (vidc.h_border_start << 14));
  264. vidc_writel(0x8c000000 | (vidc.h_display_start << 14));
  265. vidc_writel(0x90000000 | (vidc.h_display_end << 14));
  266. vidc_writel(0x94000000 | (vidc.h_border_end << 14));
  267. vidc_writel(0x98000000);
  268. vidc_writel(0x9c000000 | (vidc.h_interlace << 14));
  269. vidc_writel(0xa0000000 | (vidc.v_cycle << 14));
  270. vidc_writel(0xa4000000 | (vidc.v_sync_width << 14));
  271. vidc_writel(0xa8000000 | (vidc.v_border_start << 14));
  272. vidc_writel(0xac000000 | (vidc.v_display_start << 14));
  273. vidc_writel(0xb0000000 | (vidc.v_display_end << 14));
  274. vidc_writel(0xb4000000 | (vidc.v_border_end << 14));
  275. vidc_writel(0xb8000000);
  276. vidc_writel(0xbc000000);
  277. }
  278. #ifdef DEBUG_MODE_SELECTION
  279. printk(KERN_DEBUG "VIDC registers for %dx%dx%d:\n", var->xres,
  280. var->yres, var->bits_per_pixel);
  281. printk(KERN_DEBUG " H-cycle : %d\n", vidc.h_cycle);
  282. printk(KERN_DEBUG " H-sync-width : %d\n", vidc.h_sync_width);
  283. printk(KERN_DEBUG " H-border-start : %d\n", vidc.h_border_start);
  284. printk(KERN_DEBUG " H-display-start : %d\n", vidc.h_display_start);
  285. printk(KERN_DEBUG " H-display-end : %d\n", vidc.h_display_end);
  286. printk(KERN_DEBUG " H-border-end : %d\n", vidc.h_border_end);
  287. printk(KERN_DEBUG " H-interlace : %d\n", vidc.h_interlace);
  288. printk(KERN_DEBUG " V-cycle : %d\n", vidc.v_cycle);
  289. printk(KERN_DEBUG " V-sync-width : %d\n", vidc.v_sync_width);
  290. printk(KERN_DEBUG " V-border-start : %d\n", vidc.v_border_start);
  291. printk(KERN_DEBUG " V-display-start : %d\n", vidc.v_display_start);
  292. printk(KERN_DEBUG " V-display-end : %d\n", vidc.v_display_end);
  293. printk(KERN_DEBUG " V-border-end : %d\n", vidc.v_border_end);
  294. printk(KERN_DEBUG " VIDC Ctrl (E) : 0x%08X\n", vidc_ctl);
  295. printk(KERN_DEBUG " IOEB Ctrl : 0x%08X\n", vid_ctl);
  296. #endif
  297. }
  298. static int
  299. acornfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  300. u_int trans, struct fb_info *info)
  301. {
  302. union palette pal;
  303. if (regno >= current_par.palette_size)
  304. return 1;
  305. pal.p = 0;
  306. pal.vidc.reg = regno;
  307. pal.vidc.red = red >> 12;
  308. pal.vidc.green = green >> 12;
  309. pal.vidc.blue = blue >> 12;
  310. current_par.palette[regno] = pal;
  311. vidc_writel(pal.p);
  312. return 0;
  313. }
  314. #endif
  315. #ifdef HAS_VIDC20
  316. #include <asm/arch/acornfb.h>
  317. #define MAX_SIZE 2*1024*1024
  318. /* VIDC20 has a different set of rules from the VIDC:
  319. * hcr : must be multiple of 4
  320. * hswr : must be even
  321. * hdsr : must be even
  322. * hder : must be even
  323. * vcr : >= 2, (interlace, must be odd)
  324. * vswr : >= 1
  325. * vdsr : >= 1
  326. * vder : >= vdsr
  327. */
  328. static void acornfb_set_timing(struct fb_info *info)
  329. {
  330. struct fb_var_screeninfo *var = &info->var;
  331. struct vidc_timing vidc;
  332. u_int vcr, fsize;
  333. u_int ext_ctl, dat_ctl;
  334. u_int words_per_line;
  335. memset(&vidc, 0, sizeof(vidc));
  336. vidc.h_sync_width = var->hsync_len - 8;
  337. vidc.h_border_start = vidc.h_sync_width + var->left_margin + 8 - 12;
  338. vidc.h_display_start = vidc.h_border_start + 12 - 18;
  339. vidc.h_display_end = vidc.h_display_start + var->xres;
  340. vidc.h_border_end = vidc.h_display_end + 18 - 12;
  341. vidc.h_cycle = vidc.h_border_end + var->right_margin + 12 - 8;
  342. vidc.h_interlace = vidc.h_cycle / 2;
  343. vidc.v_sync_width = var->vsync_len - 1;
  344. vidc.v_border_start = vidc.v_sync_width + var->upper_margin;
  345. vidc.v_display_start = vidc.v_border_start;
  346. vidc.v_display_end = vidc.v_display_start + var->yres;
  347. vidc.v_border_end = vidc.v_display_end;
  348. vidc.control = acornfb_default_control();
  349. vcr = var->vsync_len + var->upper_margin + var->yres +
  350. var->lower_margin;
  351. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  352. vidc.v_cycle = (vcr - 3) / 2;
  353. vidc.control |= VIDC20_CTRL_INT;
  354. } else
  355. vidc.v_cycle = vcr - 2;
  356. switch (var->bits_per_pixel) {
  357. case 1: vidc.control |= VIDC20_CTRL_1BPP; break;
  358. case 2: vidc.control |= VIDC20_CTRL_2BPP; break;
  359. case 4: vidc.control |= VIDC20_CTRL_4BPP; break;
  360. default:
  361. case 8: vidc.control |= VIDC20_CTRL_8BPP; break;
  362. case 16: vidc.control |= VIDC20_CTRL_16BPP; break;
  363. case 32: vidc.control |= VIDC20_CTRL_32BPP; break;
  364. }
  365. acornfb_vidc20_find_rates(&vidc, var);
  366. fsize = var->vsync_len + var->upper_margin + var->lower_margin - 1;
  367. if (memcmp(&current_vidc, &vidc, sizeof(vidc))) {
  368. current_vidc = vidc;
  369. vidc_writel(VIDC20_CTRL| vidc.control);
  370. vidc_writel(0xd0000000 | vidc.pll_ctl);
  371. vidc_writel(0x80000000 | vidc.h_cycle);
  372. vidc_writel(0x81000000 | vidc.h_sync_width);
  373. vidc_writel(0x82000000 | vidc.h_border_start);
  374. vidc_writel(0x83000000 | vidc.h_display_start);
  375. vidc_writel(0x84000000 | vidc.h_display_end);
  376. vidc_writel(0x85000000 | vidc.h_border_end);
  377. vidc_writel(0x86000000);
  378. vidc_writel(0x87000000 | vidc.h_interlace);
  379. vidc_writel(0x90000000 | vidc.v_cycle);
  380. vidc_writel(0x91000000 | vidc.v_sync_width);
  381. vidc_writel(0x92000000 | vidc.v_border_start);
  382. vidc_writel(0x93000000 | vidc.v_display_start);
  383. vidc_writel(0x94000000 | vidc.v_display_end);
  384. vidc_writel(0x95000000 | vidc.v_border_end);
  385. vidc_writel(0x96000000);
  386. vidc_writel(0x97000000);
  387. }
  388. iomd_writel(fsize, IOMD_FSIZE);
  389. ext_ctl = acornfb_default_econtrol();
  390. if (var->sync & FB_SYNC_COMP_HIGH_ACT) /* should be FB_SYNC_COMP */
  391. ext_ctl |= VIDC20_ECTL_HS_NCSYNC | VIDC20_ECTL_VS_NCSYNC;
  392. else {
  393. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  394. ext_ctl |= VIDC20_ECTL_HS_HSYNC;
  395. else
  396. ext_ctl |= VIDC20_ECTL_HS_NHSYNC;
  397. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  398. ext_ctl |= VIDC20_ECTL_VS_VSYNC;
  399. else
  400. ext_ctl |= VIDC20_ECTL_VS_NVSYNC;
  401. }
  402. vidc_writel(VIDC20_ECTL | ext_ctl);
  403. words_per_line = var->xres * var->bits_per_pixel / 32;
  404. if (current_par.using_vram && info->fix.smem_len == 2048*1024)
  405. words_per_line /= 2;
  406. /* RiscPC doesn't use the VIDC's VRAM control. */
  407. dat_ctl = VIDC20_DCTL_VRAM_DIS | VIDC20_DCTL_SNA | words_per_line;
  408. /* The data bus width is dependent on both the type
  409. * and amount of video memory.
  410. * DRAM 32bit low
  411. * 1MB VRAM 32bit
  412. * 2MB VRAM 64bit
  413. */
  414. if (current_par.using_vram && current_par.vram_half_sam == 2048)
  415. dat_ctl |= VIDC20_DCTL_BUS_D63_0;
  416. else
  417. dat_ctl |= VIDC20_DCTL_BUS_D31_0;
  418. vidc_writel(VIDC20_DCTL | dat_ctl);
  419. #ifdef DEBUG_MODE_SELECTION
  420. printk(KERN_DEBUG "VIDC registers for %dx%dx%d:\n", var->xres,
  421. var->yres, var->bits_per_pixel);
  422. printk(KERN_DEBUG " H-cycle : %d\n", vidc.h_cycle);
  423. printk(KERN_DEBUG " H-sync-width : %d\n", vidc.h_sync_width);
  424. printk(KERN_DEBUG " H-border-start : %d\n", vidc.h_border_start);
  425. printk(KERN_DEBUG " H-display-start : %d\n", vidc.h_display_start);
  426. printk(KERN_DEBUG " H-display-end : %d\n", vidc.h_display_end);
  427. printk(KERN_DEBUG " H-border-end : %d\n", vidc.h_border_end);
  428. printk(KERN_DEBUG " H-interlace : %d\n", vidc.h_interlace);
  429. printk(KERN_DEBUG " V-cycle : %d\n", vidc.v_cycle);
  430. printk(KERN_DEBUG " V-sync-width : %d\n", vidc.v_sync_width);
  431. printk(KERN_DEBUG " V-border-start : %d\n", vidc.v_border_start);
  432. printk(KERN_DEBUG " V-display-start : %d\n", vidc.v_display_start);
  433. printk(KERN_DEBUG " V-display-end : %d\n", vidc.v_display_end);
  434. printk(KERN_DEBUG " V-border-end : %d\n", vidc.v_border_end);
  435. printk(KERN_DEBUG " Ext Ctrl (C) : 0x%08X\n", ext_ctl);
  436. printk(KERN_DEBUG " PLL Ctrl (D) : 0x%08X\n", vidc.pll_ctl);
  437. printk(KERN_DEBUG " Ctrl (E) : 0x%08X\n", vidc.control);
  438. printk(KERN_DEBUG " Data Ctrl (F) : 0x%08X\n", dat_ctl);
  439. printk(KERN_DEBUG " Fsize : 0x%08X\n", fsize);
  440. #endif
  441. }
  442. /*
  443. * We have to take note of the VIDC20's 16-bit palette here.
  444. * The VIDC20 looks up a 16 bit pixel as follows:
  445. *
  446. * bits 111111
  447. * 5432109876543210
  448. * red ++++++++ (8 bits, 7 to 0)
  449. * green ++++++++ (8 bits, 11 to 4)
  450. * blue ++++++++ (8 bits, 15 to 8)
  451. *
  452. * We use a pixel which looks like:
  453. *
  454. * bits 111111
  455. * 5432109876543210
  456. * red +++++ (5 bits, 4 to 0)
  457. * green +++++ (5 bits, 9 to 5)
  458. * blue +++++ (5 bits, 14 to 10)
  459. */
  460. static int
  461. acornfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  462. u_int trans, struct fb_info *info)
  463. {
  464. union palette pal;
  465. if (regno >= current_par.palette_size)
  466. return 1;
  467. if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  468. u32 pseudo_val;
  469. pseudo_val = regno << info->var.red.offset;
  470. pseudo_val |= regno << info->var.green.offset;
  471. pseudo_val |= regno << info->var.blue.offset;
  472. ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
  473. }
  474. pal.p = 0;
  475. pal.vidc20.red = red >> 8;
  476. pal.vidc20.green = green >> 8;
  477. pal.vidc20.blue = blue >> 8;
  478. current_par.palette[regno] = pal;
  479. if (info->var.bits_per_pixel == 16) {
  480. int i;
  481. pal.p = 0;
  482. vidc_writel(0x10000000);
  483. for (i = 0; i < 256; i += 1) {
  484. pal.vidc20.red = current_par.palette[ i & 31].vidc20.red;
  485. pal.vidc20.green = current_par.palette[(i >> 1) & 31].vidc20.green;
  486. pal.vidc20.blue = current_par.palette[(i >> 2) & 31].vidc20.blue;
  487. vidc_writel(pal.p);
  488. /* Palette register pointer auto-increments */
  489. }
  490. } else {
  491. vidc_writel(0x10000000 | regno);
  492. vidc_writel(pal.p);
  493. }
  494. return 0;
  495. }
  496. #endif
  497. /*
  498. * Before selecting the timing parameters, adjust
  499. * the resolution to fit the rules.
  500. */
  501. static int
  502. acornfb_adjust_timing(struct fb_info *info, struct fb_var_screeninfo *var, u_int fontht)
  503. {
  504. u_int font_line_len, sam_size, min_size, size, nr_y;
  505. /* xres must be even */
  506. var->xres = (var->xres + 1) & ~1;
  507. /*
  508. * We don't allow xres_virtual to differ from xres
  509. */
  510. var->xres_virtual = var->xres;
  511. var->xoffset = 0;
  512. if (current_par.using_vram)
  513. sam_size = current_par.vram_half_sam * 2;
  514. else
  515. sam_size = 16;
  516. /*
  517. * Now, find a value for yres_virtual which allows
  518. * us to do ywrap scrolling. The value of
  519. * yres_virtual must be such that the end of the
  520. * displayable frame buffer must be aligned with
  521. * the start of a font line.
  522. */
  523. font_line_len = var->xres * var->bits_per_pixel * fontht / 8;
  524. min_size = var->xres * var->yres * var->bits_per_pixel / 8;
  525. /*
  526. * If minimum screen size is greater than that we have
  527. * available, reject it.
  528. */
  529. if (min_size > info->fix.smem_len)
  530. return -EINVAL;
  531. /* Find int 'y', such that y * fll == s * sam < maxsize
  532. * y = s * sam / fll; s = maxsize / sam
  533. */
  534. for (size = info->fix.smem_len;
  535. nr_y = size / font_line_len, min_size <= size;
  536. size -= sam_size) {
  537. if (nr_y * font_line_len == size)
  538. break;
  539. }
  540. nr_y *= fontht;
  541. if (var->accel_flags & FB_ACCELF_TEXT) {
  542. if (min_size > size) {
  543. /*
  544. * failed, use ypan
  545. */
  546. size = info->fix.smem_len;
  547. var->yres_virtual = size / (font_line_len / fontht);
  548. } else
  549. var->yres_virtual = nr_y;
  550. } else if (var->yres_virtual > nr_y)
  551. var->yres_virtual = nr_y;
  552. current_par.screen_end = info->fix.smem_start + size;
  553. /*
  554. * Fix yres & yoffset if needed.
  555. */
  556. if (var->yres > var->yres_virtual)
  557. var->yres = var->yres_virtual;
  558. if (var->vmode & FB_VMODE_YWRAP) {
  559. if (var->yoffset > var->yres_virtual)
  560. var->yoffset = var->yres_virtual;
  561. } else {
  562. if (var->yoffset + var->yres > var->yres_virtual)
  563. var->yoffset = var->yres_virtual - var->yres;
  564. }
  565. /* hsync_len must be even */
  566. var->hsync_len = (var->hsync_len + 1) & ~1;
  567. #ifdef HAS_VIDC
  568. /* left_margin must be odd */
  569. if ((var->left_margin & 1) == 0) {
  570. var->left_margin -= 1;
  571. var->right_margin += 1;
  572. }
  573. /* right_margin must be odd */
  574. var->right_margin |= 1;
  575. #elif defined(HAS_VIDC20)
  576. /* left_margin must be even */
  577. if (var->left_margin & 1) {
  578. var->left_margin += 1;
  579. var->right_margin -= 1;
  580. }
  581. /* right_margin must be even */
  582. if (var->right_margin & 1)
  583. var->right_margin += 1;
  584. #endif
  585. if (var->vsync_len < 1)
  586. var->vsync_len = 1;
  587. return 0;
  588. }
  589. static int
  590. acornfb_validate_timing(struct fb_var_screeninfo *var,
  591. struct fb_monspecs *monspecs)
  592. {
  593. unsigned long hs, vs;
  594. /*
  595. * hs(Hz) = 10^12 / (pixclock * xtotal)
  596. * vs(Hz) = hs(Hz) / ytotal
  597. *
  598. * No need to do long long divisions or anything
  599. * like that if you factor it correctly
  600. */
  601. hs = 1953125000 / var->pixclock;
  602. hs = hs * 512 /
  603. (var->xres + var->left_margin + var->right_margin + var->hsync_len);
  604. vs = hs /
  605. (var->yres + var->upper_margin + var->lower_margin + var->vsync_len);
  606. return (vs >= monspecs->vfmin && vs <= monspecs->vfmax &&
  607. hs >= monspecs->hfmin && hs <= monspecs->hfmax) ? 0 : -EINVAL;
  608. }
  609. static inline void
  610. acornfb_update_dma(struct fb_info *info, struct fb_var_screeninfo *var)
  611. {
  612. u_int off = var->yoffset * info->fix.line_length;
  613. #if defined(HAS_MEMC)
  614. memc_write(VDMA_INIT, off >> 2);
  615. #elif defined(HAS_IOMD)
  616. iomd_writel(info->fix.smem_start + off, IOMD_VIDINIT);
  617. #endif
  618. }
  619. static int
  620. acornfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  621. {
  622. u_int fontht;
  623. int err;
  624. /*
  625. * FIXME: Find the font height
  626. */
  627. fontht = 8;
  628. var->red.msb_right = 0;
  629. var->green.msb_right = 0;
  630. var->blue.msb_right = 0;
  631. var->transp.msb_right = 0;
  632. switch (var->bits_per_pixel) {
  633. case 1: case 2: case 4: case 8:
  634. var->red.offset = 0;
  635. var->red.length = var->bits_per_pixel;
  636. var->green = var->red;
  637. var->blue = var->red;
  638. var->transp.offset = 0;
  639. var->transp.length = 0;
  640. break;
  641. #ifdef HAS_VIDC20
  642. case 16:
  643. var->red.offset = 0;
  644. var->red.length = 5;
  645. var->green.offset = 5;
  646. var->green.length = 5;
  647. var->blue.offset = 10;
  648. var->blue.length = 5;
  649. var->transp.offset = 15;
  650. var->transp.length = 1;
  651. break;
  652. case 32:
  653. var->red.offset = 0;
  654. var->red.length = 8;
  655. var->green.offset = 8;
  656. var->green.length = 8;
  657. var->blue.offset = 16;
  658. var->blue.length = 8;
  659. var->transp.offset = 24;
  660. var->transp.length = 4;
  661. break;
  662. #endif
  663. default:
  664. return -EINVAL;
  665. }
  666. /*
  667. * Check to see if the pixel rate is valid.
  668. */
  669. if (!acornfb_valid_pixrate(var))
  670. return -EINVAL;
  671. /*
  672. * Validate and adjust the resolution to
  673. * match the video generator hardware.
  674. */
  675. err = acornfb_adjust_timing(info, var, fontht);
  676. if (err)
  677. return err;
  678. /*
  679. * Validate the timing against the
  680. * monitor hardware.
  681. */
  682. return acornfb_validate_timing(var, &info->monspecs);
  683. }
  684. static int acornfb_set_par(struct fb_info *info)
  685. {
  686. switch (info->var.bits_per_pixel) {
  687. case 1:
  688. current_par.palette_size = 2;
  689. info->fix.visual = FB_VISUAL_MONO10;
  690. break;
  691. case 2:
  692. current_par.palette_size = 4;
  693. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  694. break;
  695. case 4:
  696. current_par.palette_size = 16;
  697. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  698. break;
  699. case 8:
  700. current_par.palette_size = VIDC_PALETTE_SIZE;
  701. #ifdef HAS_VIDC
  702. info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  703. #else
  704. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  705. #endif
  706. break;
  707. #ifdef HAS_VIDC20
  708. case 16:
  709. current_par.palette_size = 32;
  710. info->fix.visual = FB_VISUAL_DIRECTCOLOR;
  711. break;
  712. case 32:
  713. current_par.palette_size = VIDC_PALETTE_SIZE;
  714. info->fix.visual = FB_VISUAL_DIRECTCOLOR;
  715. break;
  716. #endif
  717. default:
  718. BUG();
  719. }
  720. info->fix.line_length = (info->var.xres * info->var.bits_per_pixel) / 8;
  721. #if defined(HAS_MEMC)
  722. {
  723. unsigned long size = info->fix.smem_len - VDMA_XFERSIZE;
  724. memc_write(VDMA_START, 0);
  725. memc_write(VDMA_END, size >> 2);
  726. }
  727. #elif defined(HAS_IOMD)
  728. {
  729. unsigned long start, size;
  730. u_int control;
  731. start = info->fix.smem_start;
  732. size = current_par.screen_end;
  733. if (current_par.using_vram) {
  734. size -= current_par.vram_half_sam;
  735. control = DMA_CR_E | (current_par.vram_half_sam / 256);
  736. } else {
  737. size -= 16;
  738. control = DMA_CR_E | DMA_CR_D | 16;
  739. }
  740. iomd_writel(start, IOMD_VIDSTART);
  741. iomd_writel(size, IOMD_VIDEND);
  742. iomd_writel(control, IOMD_VIDCR);
  743. }
  744. #endif
  745. acornfb_update_dma(info, &info->var);
  746. acornfb_set_timing(info);
  747. return 0;
  748. }
  749. static int
  750. acornfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  751. {
  752. u_int y_bottom = var->yoffset;
  753. if (!(var->vmode & FB_VMODE_YWRAP))
  754. y_bottom += var->yres;
  755. BUG_ON(y_bottom > var->yres_virtual);
  756. acornfb_update_dma(info, var);
  757. return 0;
  758. }
  759. /*
  760. * Note that we are entered with the kernel locked.
  761. */
  762. static int
  763. acornfb_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
  764. {
  765. unsigned long off, start;
  766. u32 len;
  767. off = vma->vm_pgoff << PAGE_SHIFT;
  768. start = info->fix.smem_start;
  769. len = PAGE_ALIGN(start & ~PAGE_MASK) + info->fix.smem_len;
  770. start &= PAGE_MASK;
  771. if ((vma->vm_end - vma->vm_start + off) > len)
  772. return -EINVAL;
  773. off += start;
  774. vma->vm_pgoff = off >> PAGE_SHIFT;
  775. /* This is an IO map - tell maydump to skip this VMA */
  776. vma->vm_flags |= VM_IO;
  777. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  778. /*
  779. * Don't alter the page protection flags; we want to keep the area
  780. * cached for better performance. This does mean that we may miss
  781. * some updates to the screen occasionally, but process switches
  782. * should cause the caches and buffers to be flushed often enough.
  783. */
  784. if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  785. vma->vm_end - vma->vm_start,
  786. vma->vm_page_prot))
  787. return -EAGAIN;
  788. return 0;
  789. }
  790. static struct fb_ops acornfb_ops = {
  791. .owner = THIS_MODULE,
  792. .fb_check_var = acornfb_check_var,
  793. .fb_set_par = acornfb_set_par,
  794. .fb_setcolreg = acornfb_setcolreg,
  795. .fb_pan_display = acornfb_pan_display,
  796. .fb_fillrect = cfb_fillrect,
  797. .fb_copyarea = cfb_copyarea,
  798. .fb_imageblit = cfb_imageblit,
  799. .fb_mmap = acornfb_mmap,
  800. };
  801. /*
  802. * Everything after here is initialisation!!!
  803. */
  804. static struct fb_videomode modedb[] __initdata = {
  805. { /* 320x256 @ 50Hz */
  806. NULL, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
  807. FB_SYNC_COMP_HIGH_ACT,
  808. FB_VMODE_NONINTERLACED
  809. }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
  810. NULL, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
  811. 0,
  812. FB_VMODE_NONINTERLACED
  813. }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
  814. NULL, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
  815. 0,
  816. FB_VMODE_NONINTERLACED
  817. }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
  818. NULL, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
  819. 0,
  820. FB_VMODE_NONINTERLACED
  821. }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
  822. NULL, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
  823. 0,
  824. FB_VMODE_NONINTERLACED
  825. }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
  826. NULL, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
  827. 0,
  828. FB_VMODE_NONINTERLACED
  829. }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
  830. NULL, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
  831. 0,
  832. FB_VMODE_NONINTERLACED
  833. }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
  834. NULL, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
  835. 0,
  836. FB_VMODE_NONINTERLACED
  837. }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
  838. NULL, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
  839. 0,
  840. FB_VMODE_NONINTERLACED
  841. }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
  842. NULL, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
  843. 0,
  844. FB_VMODE_NONINTERLACED
  845. }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
  846. NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
  847. 0,
  848. FB_VMODE_NONINTERLACED
  849. }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
  850. NULL, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
  851. 0,
  852. FB_VMODE_NONINTERLACED
  853. }
  854. };
  855. static struct fb_videomode __initdata
  856. acornfb_default_mode = {
  857. .name = NULL,
  858. .refresh = 60,
  859. .xres = 640,
  860. .yres = 480,
  861. .pixclock = 39722,
  862. .left_margin = 56,
  863. .right_margin = 16,
  864. .upper_margin = 34,
  865. .lower_margin = 9,
  866. .hsync_len = 88,
  867. .vsync_len = 2,
  868. .sync = 0,
  869. .vmode = FB_VMODE_NONINTERLACED
  870. };
  871. static void __init acornfb_init_fbinfo(void)
  872. {
  873. static int first = 1;
  874. if (!first)
  875. return;
  876. first = 0;
  877. fb_info.fbops = &acornfb_ops;
  878. fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  879. fb_info.pseudo_palette = current_par.pseudo_palette;
  880. strcpy(fb_info.fix.id, "Acorn");
  881. fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
  882. fb_info.fix.type_aux = 0;
  883. fb_info.fix.xpanstep = 0;
  884. fb_info.fix.ypanstep = 1;
  885. fb_info.fix.ywrapstep = 1;
  886. fb_info.fix.line_length = 0;
  887. fb_info.fix.accel = FB_ACCEL_NONE;
  888. /*
  889. * setup initial parameters
  890. */
  891. memset(&fb_info.var, 0, sizeof(fb_info.var));
  892. #if defined(HAS_VIDC20)
  893. fb_info.var.red.length = 8;
  894. fb_info.var.transp.length = 4;
  895. #elif defined(HAS_VIDC)
  896. fb_info.var.red.length = 4;
  897. fb_info.var.transp.length = 1;
  898. #endif
  899. fb_info.var.green = fb_info.var.red;
  900. fb_info.var.blue = fb_info.var.red;
  901. fb_info.var.nonstd = 0;
  902. fb_info.var.activate = FB_ACTIVATE_NOW;
  903. fb_info.var.height = -1;
  904. fb_info.var.width = -1;
  905. fb_info.var.vmode = FB_VMODE_NONINTERLACED;
  906. fb_info.var.accel_flags = FB_ACCELF_TEXT;
  907. current_par.dram_size = 0;
  908. current_par.montype = -1;
  909. current_par.dpms = 0;
  910. }
  911. /*
  912. * setup acornfb options:
  913. *
  914. * mon:hmin-hmax:vmin-vmax:dpms:width:height
  915. * Set monitor parameters:
  916. * hmin = horizontal minimum frequency (Hz)
  917. * hmax = horizontal maximum frequency (Hz) (optional)
  918. * vmin = vertical minimum frequency (Hz)
  919. * vmax = vertical maximum frequency (Hz) (optional)
  920. * dpms = DPMS supported? (optional)
  921. * width = width of picture in mm. (optional)
  922. * height = height of picture in mm. (optional)
  923. *
  924. * montype:type
  925. * Set RISC-OS style monitor type:
  926. * 0 (or tv) - TV frequency
  927. * 1 (or multi) - Multi frequency
  928. * 2 (or hires) - Hi-res monochrome
  929. * 3 (or vga) - VGA
  930. * 4 (or svga) - SVGA
  931. * auto, or option missing
  932. * - try hardware detect
  933. *
  934. * dram:size
  935. * Set the amount of DRAM to use for the frame buffer
  936. * (even if you have VRAM).
  937. * size can optionally be followed by 'M' or 'K' for
  938. * MB or KB respectively.
  939. */
  940. static void __init
  941. acornfb_parse_mon(char *opt)
  942. {
  943. char *p = opt;
  944. current_par.montype = -2;
  945. fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
  946. if (*p == '-')
  947. fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
  948. else
  949. fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
  950. if (*p != ':')
  951. goto bad;
  952. fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
  953. if (*p == '-')
  954. fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
  955. else
  956. fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
  957. if (*p != ':')
  958. goto check_values;
  959. fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
  960. if (*p != ':')
  961. goto check_values;
  962. fb_info.var.width = simple_strtoul(p + 1, &p, 0);
  963. if (*p != ':')
  964. goto check_values;
  965. fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
  966. check_values:
  967. if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
  968. fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
  969. goto bad;
  970. return;
  971. bad:
  972. printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
  973. current_par.montype = -1;
  974. }
  975. static void __init
  976. acornfb_parse_montype(char *opt)
  977. {
  978. current_par.montype = -2;
  979. if (strncmp(opt, "tv", 2) == 0) {
  980. opt += 2;
  981. current_par.montype = 0;
  982. } else if (strncmp(opt, "multi", 5) == 0) {
  983. opt += 5;
  984. current_par.montype = 1;
  985. } else if (strncmp(opt, "hires", 5) == 0) {
  986. opt += 5;
  987. current_par.montype = 2;
  988. } else if (strncmp(opt, "vga", 3) == 0) {
  989. opt += 3;
  990. current_par.montype = 3;
  991. } else if (strncmp(opt, "svga", 4) == 0) {
  992. opt += 4;
  993. current_par.montype = 4;
  994. } else if (strncmp(opt, "auto", 4) == 0) {
  995. opt += 4;
  996. current_par.montype = -1;
  997. } else if (isdigit(*opt))
  998. current_par.montype = simple_strtoul(opt, &opt, 0);
  999. if (current_par.montype == -2 ||
  1000. current_par.montype > NR_MONTYPES) {
  1001. printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
  1002. opt);
  1003. current_par.montype = -1;
  1004. } else
  1005. if (opt && *opt) {
  1006. if (strcmp(opt, ",dpms") == 0)
  1007. current_par.dpms = 1;
  1008. else
  1009. printk(KERN_ERR
  1010. "acornfb: unknown monitor option: %s\n",
  1011. opt);
  1012. }
  1013. }
  1014. static void __init
  1015. acornfb_parse_dram(char *opt)
  1016. {
  1017. unsigned int size;
  1018. size = simple_strtoul(opt, &opt, 0);
  1019. if (opt) {
  1020. switch (*opt) {
  1021. case 'M':
  1022. case 'm':
  1023. size *= 1024;
  1024. case 'K':
  1025. case 'k':
  1026. size *= 1024;
  1027. default:
  1028. break;
  1029. }
  1030. }
  1031. current_par.dram_size = size;
  1032. }
  1033. static struct options {
  1034. char *name;
  1035. void (*parse)(char *opt);
  1036. } opt_table[] __initdata = {
  1037. { "mon", acornfb_parse_mon },
  1038. { "montype", acornfb_parse_montype },
  1039. { "dram", acornfb_parse_dram },
  1040. { NULL, NULL }
  1041. };
  1042. int __init
  1043. acornfb_setup(char *options)
  1044. {
  1045. struct options *optp;
  1046. char *opt;
  1047. if (!options || !*options)
  1048. return 0;
  1049. acornfb_init_fbinfo();
  1050. while ((opt = strsep(&options, ",")) != NULL) {
  1051. if (!*opt)
  1052. continue;
  1053. for (optp = opt_table; optp->name; optp++) {
  1054. int optlen;
  1055. optlen = strlen(optp->name);
  1056. if (strncmp(opt, optp->name, optlen) == 0 &&
  1057. opt[optlen] == ':') {
  1058. optp->parse(opt + optlen + 1);
  1059. break;
  1060. }
  1061. }
  1062. if (!optp->name)
  1063. printk(KERN_ERR "acornfb: unknown parameter: %s\n",
  1064. opt);
  1065. }
  1066. return 0;
  1067. }
  1068. /*
  1069. * Detect type of monitor connected
  1070. * For now, we just assume SVGA
  1071. */
  1072. static int __init
  1073. acornfb_detect_monitortype(void)
  1074. {
  1075. return 4;
  1076. }
  1077. /*
  1078. * This enables the unused memory to be freed on older Acorn machines.
  1079. * We are freeing memory on behalf of the architecture initialisation
  1080. * code here.
  1081. */
  1082. static inline void
  1083. free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
  1084. {
  1085. int mb_freed = 0;
  1086. /*
  1087. * Align addresses
  1088. */
  1089. virtual_start = PAGE_ALIGN(virtual_start);
  1090. virtual_end = PAGE_ALIGN(virtual_end);
  1091. while (virtual_start < virtual_end) {
  1092. struct page *page;
  1093. /*
  1094. * Clear page reserved bit,
  1095. * set count to 1, and free
  1096. * the page.
  1097. */
  1098. page = virt_to_page(virtual_start);
  1099. ClearPageReserved(page);
  1100. set_page_count(page, 1);
  1101. free_page(virtual_start);
  1102. virtual_start += PAGE_SIZE;
  1103. mb_freed += PAGE_SIZE / 1024;
  1104. }
  1105. printk("acornfb: freed %dK memory\n", mb_freed);
  1106. }
  1107. static int __init acornfb_probe(struct device *dev)
  1108. {
  1109. unsigned long size;
  1110. u_int h_sync, v_sync;
  1111. int rc, i;
  1112. char *option = NULL;
  1113. if (fb_get_options("acornfb", &option))
  1114. return -ENODEV;
  1115. acornfb_setup(option);
  1116. acornfb_init_fbinfo();
  1117. current_par.dev = dev;
  1118. if (current_par.montype == -1)
  1119. current_par.montype = acornfb_detect_monitortype();
  1120. if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
  1121. current_par.montype = 4;
  1122. if (current_par.montype >= 0) {
  1123. fb_info.monspecs = monspecs[current_par.montype];
  1124. fb_info.monspecs.dpms = current_par.dpms;
  1125. }
  1126. /*
  1127. * Try to select a suitable default mode
  1128. */
  1129. for (i = 0; i < sizeof(modedb) / sizeof(*modedb); i++) {
  1130. unsigned long hs;
  1131. hs = modedb[i].refresh *
  1132. (modedb[i].yres + modedb[i].upper_margin +
  1133. modedb[i].lower_margin + modedb[i].vsync_len);
  1134. if (modedb[i].xres == DEFAULT_XRES &&
  1135. modedb[i].yres == DEFAULT_YRES &&
  1136. modedb[i].refresh >= fb_info.monspecs.vfmin &&
  1137. modedb[i].refresh <= fb_info.monspecs.vfmax &&
  1138. hs >= fb_info.monspecs.hfmin &&
  1139. hs <= fb_info.monspecs.hfmax) {
  1140. acornfb_default_mode = modedb[i];
  1141. break;
  1142. }
  1143. }
  1144. fb_info.screen_base = (char *)SCREEN_BASE;
  1145. fb_info.fix.smem_start = SCREEN_START;
  1146. current_par.using_vram = 0;
  1147. /*
  1148. * If vram_size is set, we are using VRAM in
  1149. * a Risc PC. However, if the user has specified
  1150. * an amount of DRAM then use that instead.
  1151. */
  1152. if (vram_size && !current_par.dram_size) {
  1153. size = vram_size;
  1154. current_par.vram_half_sam = vram_size / 1024;
  1155. current_par.using_vram = 1;
  1156. } else if (current_par.dram_size)
  1157. size = current_par.dram_size;
  1158. else
  1159. size = MAX_SIZE;
  1160. /*
  1161. * Limit maximum screen size.
  1162. */
  1163. if (size > MAX_SIZE)
  1164. size = MAX_SIZE;
  1165. size = PAGE_ALIGN(size);
  1166. #if defined(HAS_VIDC20)
  1167. if (!current_par.using_vram) {
  1168. dma_addr_t handle;
  1169. void *base;
  1170. /*
  1171. * RiscPC needs to allocate the DRAM memory
  1172. * for the framebuffer if we are not using
  1173. * VRAM.
  1174. */
  1175. base = dma_alloc_writecombine(current_par.dev, size, &handle,
  1176. GFP_KERNEL);
  1177. if (base == NULL) {
  1178. printk(KERN_ERR "acornfb: unable to allocate screen "
  1179. "memory\n");
  1180. return -ENOMEM;
  1181. }
  1182. fb_info.screen_base = base;
  1183. fb_info.fix.smem_start = handle;
  1184. }
  1185. #endif
  1186. #if defined(HAS_VIDC)
  1187. /*
  1188. * Archimedes/A5000 machines use a fixed address for their
  1189. * framebuffers. Free unused pages
  1190. */
  1191. free_unused_pages(PAGE_OFFSET + size, PAGE_OFFSET + MAX_SIZE);
  1192. #endif
  1193. fb_info.fix.smem_len = size;
  1194. current_par.palette_size = VIDC_PALETTE_SIZE;
  1195. /*
  1196. * Lookup the timing for this resolution. If we can't
  1197. * find it, then we can't restore it if we change
  1198. * the resolution, so we disable this feature.
  1199. */
  1200. do {
  1201. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1202. sizeof(modedb) / sizeof(*modedb),
  1203. &acornfb_default_mode, DEFAULT_BPP);
  1204. /*
  1205. * If we found an exact match, all ok.
  1206. */
  1207. if (rc == 1)
  1208. break;
  1209. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1210. &acornfb_default_mode, DEFAULT_BPP);
  1211. /*
  1212. * If we found an exact match, all ok.
  1213. */
  1214. if (rc == 1)
  1215. break;
  1216. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1217. sizeof(modedb) / sizeof(*modedb),
  1218. &acornfb_default_mode, DEFAULT_BPP);
  1219. if (rc)
  1220. break;
  1221. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1222. &acornfb_default_mode, DEFAULT_BPP);
  1223. } while (0);
  1224. /*
  1225. * If we didn't find an exact match, try the
  1226. * generic database.
  1227. */
  1228. if (rc == 0) {
  1229. printk("Acornfb: no valid mode found\n");
  1230. return -EINVAL;
  1231. }
  1232. h_sync = 1953125000 / fb_info.var.pixclock;
  1233. h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
  1234. fb_info.var.right_margin + fb_info.var.hsync_len);
  1235. v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
  1236. fb_info.var.lower_margin + fb_info.var.vsync_len);
  1237. printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, "
  1238. "%d.%03dkHz, %dHz\n",
  1239. fb_info.fix.smem_len / 1024,
  1240. current_par.using_vram ? 'V' : 'D',
  1241. VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
  1242. h_sync / 1000, h_sync % 1000, v_sync);
  1243. printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
  1244. fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
  1245. fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
  1246. fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
  1247. fb_info.monspecs.dpms ? ", DPMS" : "");
  1248. if (fb_set_var(&fb_info, &fb_info.var))
  1249. printk(KERN_ERR "Acornfb: unable to set display parameters\n");
  1250. if (register_framebuffer(&fb_info) < 0)
  1251. return -EINVAL;
  1252. return 0;
  1253. }
  1254. static struct device_driver acornfb_driver = {
  1255. .name = "acornfb",
  1256. .bus = &platform_bus_type,
  1257. .probe = acornfb_probe,
  1258. };
  1259. static int __init acornfb_init(void)
  1260. {
  1261. return driver_register(&acornfb_driver);
  1262. }
  1263. module_init(acornfb_init);
  1264. MODULE_AUTHOR("Russell King");
  1265. MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
  1266. MODULE_LICENSE("GPL");