acornfb.c 35 KB

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