acornfb.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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/mm.h>
  25. #include <linux/init.h>
  26. #include <linux/fb.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/io.h>
  30. #include <linux/gfp.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] __devinitdata = {
  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[] __devinitdata = {
  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 acornfb_default_mode __devinitdata = {
  806. .name = NULL,
  807. .refresh = 60,
  808. .xres = 640,
  809. .yres = 480,
  810. .pixclock = 39722,
  811. .left_margin = 56,
  812. .right_margin = 16,
  813. .upper_margin = 34,
  814. .lower_margin = 9,
  815. .hsync_len = 88,
  816. .vsync_len = 2,
  817. .sync = 0,
  818. .vmode = FB_VMODE_NONINTERLACED
  819. };
  820. static void __devinit acornfb_init_fbinfo(void)
  821. {
  822. static int first = 1;
  823. if (!first)
  824. return;
  825. first = 0;
  826. fb_info.fbops = &acornfb_ops;
  827. fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  828. fb_info.pseudo_palette = current_par.pseudo_palette;
  829. strcpy(fb_info.fix.id, "Acorn");
  830. fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
  831. fb_info.fix.type_aux = 0;
  832. fb_info.fix.xpanstep = 0;
  833. fb_info.fix.ypanstep = 1;
  834. fb_info.fix.ywrapstep = 1;
  835. fb_info.fix.line_length = 0;
  836. fb_info.fix.accel = FB_ACCEL_NONE;
  837. /*
  838. * setup initial parameters
  839. */
  840. memset(&fb_info.var, 0, sizeof(fb_info.var));
  841. #if defined(HAS_VIDC20)
  842. fb_info.var.red.length = 8;
  843. fb_info.var.transp.length = 4;
  844. #elif defined(HAS_VIDC)
  845. fb_info.var.red.length = 4;
  846. fb_info.var.transp.length = 1;
  847. #endif
  848. fb_info.var.green = fb_info.var.red;
  849. fb_info.var.blue = fb_info.var.red;
  850. fb_info.var.nonstd = 0;
  851. fb_info.var.activate = FB_ACTIVATE_NOW;
  852. fb_info.var.height = -1;
  853. fb_info.var.width = -1;
  854. fb_info.var.vmode = FB_VMODE_NONINTERLACED;
  855. fb_info.var.accel_flags = FB_ACCELF_TEXT;
  856. current_par.dram_size = 0;
  857. current_par.montype = -1;
  858. current_par.dpms = 0;
  859. }
  860. /*
  861. * setup acornfb options:
  862. *
  863. * mon:hmin-hmax:vmin-vmax:dpms:width:height
  864. * Set monitor parameters:
  865. * hmin = horizontal minimum frequency (Hz)
  866. * hmax = horizontal maximum frequency (Hz) (optional)
  867. * vmin = vertical minimum frequency (Hz)
  868. * vmax = vertical maximum frequency (Hz) (optional)
  869. * dpms = DPMS supported? (optional)
  870. * width = width of picture in mm. (optional)
  871. * height = height of picture in mm. (optional)
  872. *
  873. * montype:type
  874. * Set RISC-OS style monitor type:
  875. * 0 (or tv) - TV frequency
  876. * 1 (or multi) - Multi frequency
  877. * 2 (or hires) - Hi-res monochrome
  878. * 3 (or vga) - VGA
  879. * 4 (or svga) - SVGA
  880. * auto, or option missing
  881. * - try hardware detect
  882. *
  883. * dram:size
  884. * Set the amount of DRAM to use for the frame buffer
  885. * (even if you have VRAM).
  886. * size can optionally be followed by 'M' or 'K' for
  887. * MB or KB respectively.
  888. */
  889. static void __devinit acornfb_parse_mon(char *opt)
  890. {
  891. char *p = opt;
  892. current_par.montype = -2;
  893. fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
  894. if (*p == '-')
  895. fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
  896. else
  897. fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
  898. if (*p != ':')
  899. goto bad;
  900. fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
  901. if (*p == '-')
  902. fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
  903. else
  904. fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
  905. if (*p != ':')
  906. goto check_values;
  907. fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
  908. if (*p != ':')
  909. goto check_values;
  910. fb_info.var.width = simple_strtoul(p + 1, &p, 0);
  911. if (*p != ':')
  912. goto check_values;
  913. fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
  914. check_values:
  915. if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
  916. fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
  917. goto bad;
  918. return;
  919. bad:
  920. printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
  921. current_par.montype = -1;
  922. }
  923. static void __devinit acornfb_parse_montype(char *opt)
  924. {
  925. current_par.montype = -2;
  926. if (strncmp(opt, "tv", 2) == 0) {
  927. opt += 2;
  928. current_par.montype = 0;
  929. } else if (strncmp(opt, "multi", 5) == 0) {
  930. opt += 5;
  931. current_par.montype = 1;
  932. } else if (strncmp(opt, "hires", 5) == 0) {
  933. opt += 5;
  934. current_par.montype = 2;
  935. } else if (strncmp(opt, "vga", 3) == 0) {
  936. opt += 3;
  937. current_par.montype = 3;
  938. } else if (strncmp(opt, "svga", 4) == 0) {
  939. opt += 4;
  940. current_par.montype = 4;
  941. } else if (strncmp(opt, "auto", 4) == 0) {
  942. opt += 4;
  943. current_par.montype = -1;
  944. } else if (isdigit(*opt))
  945. current_par.montype = simple_strtoul(opt, &opt, 0);
  946. if (current_par.montype == -2 ||
  947. current_par.montype > NR_MONTYPES) {
  948. printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
  949. opt);
  950. current_par.montype = -1;
  951. } else
  952. if (opt && *opt) {
  953. if (strcmp(opt, ",dpms") == 0)
  954. current_par.dpms = 1;
  955. else
  956. printk(KERN_ERR
  957. "acornfb: unknown monitor option: %s\n",
  958. opt);
  959. }
  960. }
  961. static void __devinit acornfb_parse_dram(char *opt)
  962. {
  963. unsigned int size;
  964. size = simple_strtoul(opt, &opt, 0);
  965. if (opt) {
  966. switch (*opt) {
  967. case 'M':
  968. case 'm':
  969. size *= 1024;
  970. case 'K':
  971. case 'k':
  972. size *= 1024;
  973. default:
  974. break;
  975. }
  976. }
  977. current_par.dram_size = size;
  978. }
  979. static struct options {
  980. char *name;
  981. void (*parse)(char *opt);
  982. } opt_table[] __devinitdata = {
  983. { "mon", acornfb_parse_mon },
  984. { "montype", acornfb_parse_montype },
  985. { "dram", acornfb_parse_dram },
  986. { NULL, NULL }
  987. };
  988. static int __devinit acornfb_setup(char *options)
  989. {
  990. struct options *optp;
  991. char *opt;
  992. if (!options || !*options)
  993. return 0;
  994. acornfb_init_fbinfo();
  995. while ((opt = strsep(&options, ",")) != NULL) {
  996. if (!*opt)
  997. continue;
  998. for (optp = opt_table; optp->name; optp++) {
  999. int optlen;
  1000. optlen = strlen(optp->name);
  1001. if (strncmp(opt, optp->name, optlen) == 0 &&
  1002. opt[optlen] == ':') {
  1003. optp->parse(opt + optlen + 1);
  1004. break;
  1005. }
  1006. }
  1007. if (!optp->name)
  1008. printk(KERN_ERR "acornfb: unknown parameter: %s\n",
  1009. opt);
  1010. }
  1011. return 0;
  1012. }
  1013. /*
  1014. * Detect type of monitor connected
  1015. * For now, we just assume SVGA
  1016. */
  1017. static int __devinit acornfb_detect_monitortype(void)
  1018. {
  1019. return 4;
  1020. }
  1021. /*
  1022. * This enables the unused memory to be freed on older Acorn machines.
  1023. * We are freeing memory on behalf of the architecture initialisation
  1024. * code here.
  1025. */
  1026. static inline void
  1027. free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
  1028. {
  1029. int mb_freed = 0;
  1030. /*
  1031. * Align addresses
  1032. */
  1033. virtual_start = PAGE_ALIGN(virtual_start);
  1034. virtual_end = PAGE_ALIGN(virtual_end);
  1035. while (virtual_start < virtual_end) {
  1036. struct page *page;
  1037. /*
  1038. * Clear page reserved bit,
  1039. * set count to 1, and free
  1040. * the page.
  1041. */
  1042. page = virt_to_page(virtual_start);
  1043. ClearPageReserved(page);
  1044. init_page_count(page);
  1045. free_page(virtual_start);
  1046. virtual_start += PAGE_SIZE;
  1047. mb_freed += PAGE_SIZE / 1024;
  1048. }
  1049. printk("acornfb: freed %dK memory\n", mb_freed);
  1050. }
  1051. static int __devinit acornfb_probe(struct platform_device *dev)
  1052. {
  1053. unsigned long size;
  1054. u_int h_sync, v_sync;
  1055. int rc, i;
  1056. char *option = NULL;
  1057. if (fb_get_options("acornfb", &option))
  1058. return -ENODEV;
  1059. acornfb_setup(option);
  1060. acornfb_init_fbinfo();
  1061. current_par.dev = &dev->dev;
  1062. if (current_par.montype == -1)
  1063. current_par.montype = acornfb_detect_monitortype();
  1064. if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
  1065. current_par.montype = 4;
  1066. if (current_par.montype >= 0) {
  1067. fb_info.monspecs = monspecs[current_par.montype];
  1068. fb_info.monspecs.dpms = current_par.dpms;
  1069. }
  1070. /*
  1071. * Try to select a suitable default mode
  1072. */
  1073. for (i = 0; i < ARRAY_SIZE(modedb); i++) {
  1074. unsigned long hs;
  1075. hs = modedb[i].refresh *
  1076. (modedb[i].yres + modedb[i].upper_margin +
  1077. modedb[i].lower_margin + modedb[i].vsync_len);
  1078. if (modedb[i].xres == DEFAULT_XRES &&
  1079. modedb[i].yres == DEFAULT_YRES &&
  1080. modedb[i].refresh >= fb_info.monspecs.vfmin &&
  1081. modedb[i].refresh <= fb_info.monspecs.vfmax &&
  1082. hs >= fb_info.monspecs.hfmin &&
  1083. hs <= fb_info.monspecs.hfmax) {
  1084. acornfb_default_mode = modedb[i];
  1085. break;
  1086. }
  1087. }
  1088. fb_info.screen_base = (char *)SCREEN_BASE;
  1089. fb_info.fix.smem_start = SCREEN_START;
  1090. current_par.using_vram = 0;
  1091. /*
  1092. * If vram_size is set, we are using VRAM in
  1093. * a Risc PC. However, if the user has specified
  1094. * an amount of DRAM then use that instead.
  1095. */
  1096. if (vram_size && !current_par.dram_size) {
  1097. size = vram_size;
  1098. current_par.vram_half_sam = vram_size / 1024;
  1099. current_par.using_vram = 1;
  1100. } else if (current_par.dram_size)
  1101. size = current_par.dram_size;
  1102. else
  1103. size = MAX_SIZE;
  1104. /*
  1105. * Limit maximum screen size.
  1106. */
  1107. if (size > MAX_SIZE)
  1108. size = MAX_SIZE;
  1109. size = PAGE_ALIGN(size);
  1110. #if defined(HAS_VIDC20)
  1111. if (!current_par.using_vram) {
  1112. dma_addr_t handle;
  1113. void *base;
  1114. /*
  1115. * RiscPC needs to allocate the DRAM memory
  1116. * for the framebuffer if we are not using
  1117. * VRAM.
  1118. */
  1119. base = dma_alloc_writecombine(current_par.dev, size, &handle,
  1120. GFP_KERNEL);
  1121. if (base == NULL) {
  1122. printk(KERN_ERR "acornfb: unable to allocate screen "
  1123. "memory\n");
  1124. return -ENOMEM;
  1125. }
  1126. fb_info.screen_base = base;
  1127. fb_info.fix.smem_start = handle;
  1128. }
  1129. #endif
  1130. #if defined(HAS_VIDC)
  1131. /*
  1132. * Archimedes/A5000 machines use a fixed address for their
  1133. * framebuffers. Free unused pages
  1134. */
  1135. free_unused_pages(PAGE_OFFSET + size, PAGE_OFFSET + MAX_SIZE);
  1136. #endif
  1137. fb_info.fix.smem_len = size;
  1138. current_par.palette_size = VIDC_PALETTE_SIZE;
  1139. /*
  1140. * Lookup the timing for this resolution. If we can't
  1141. * find it, then we can't restore it if we change
  1142. * the resolution, so we disable this feature.
  1143. */
  1144. do {
  1145. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1146. ARRAY_SIZE(modedb),
  1147. &acornfb_default_mode, DEFAULT_BPP);
  1148. /*
  1149. * If we found an exact match, all ok.
  1150. */
  1151. if (rc == 1)
  1152. break;
  1153. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1154. &acornfb_default_mode, DEFAULT_BPP);
  1155. /*
  1156. * If we found an exact match, all ok.
  1157. */
  1158. if (rc == 1)
  1159. break;
  1160. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
  1161. ARRAY_SIZE(modedb),
  1162. &acornfb_default_mode, DEFAULT_BPP);
  1163. if (rc)
  1164. break;
  1165. rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
  1166. &acornfb_default_mode, DEFAULT_BPP);
  1167. } while (0);
  1168. /*
  1169. * If we didn't find an exact match, try the
  1170. * generic database.
  1171. */
  1172. if (rc == 0) {
  1173. printk("Acornfb: no valid mode found\n");
  1174. return -EINVAL;
  1175. }
  1176. h_sync = 1953125000 / fb_info.var.pixclock;
  1177. h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
  1178. fb_info.var.right_margin + fb_info.var.hsync_len);
  1179. v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
  1180. fb_info.var.lower_margin + fb_info.var.vsync_len);
  1181. printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, "
  1182. "%d.%03dkHz, %dHz\n",
  1183. fb_info.fix.smem_len / 1024,
  1184. current_par.using_vram ? 'V' : 'D',
  1185. VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
  1186. h_sync / 1000, h_sync % 1000, v_sync);
  1187. printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
  1188. fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
  1189. fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
  1190. fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
  1191. fb_info.monspecs.dpms ? ", DPMS" : "");
  1192. if (fb_set_var(&fb_info, &fb_info.var))
  1193. printk(KERN_ERR "Acornfb: unable to set display parameters\n");
  1194. if (register_framebuffer(&fb_info) < 0)
  1195. return -EINVAL;
  1196. return 0;
  1197. }
  1198. static struct platform_driver acornfb_driver = {
  1199. .probe = acornfb_probe,
  1200. .driver = {
  1201. .name = "acornfb",
  1202. },
  1203. };
  1204. static int __init acornfb_init(void)
  1205. {
  1206. return platform_driver_register(&acornfb_driver);
  1207. }
  1208. module_init(acornfb_init);
  1209. MODULE_AUTHOR("Russell King");
  1210. MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
  1211. MODULE_LICENSE("GPL");