acornfb.c 36 KB

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